PTA A1013
第七天
A1013 Battle Over Cities (25 分)
题目内容
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of the cities connected. Given the map of cities which have all the remaining highways marked, you are supposed to tell the number of highways need to be repaired, quickly.
For example, if we have 3 cities and 2 highways connecting city1-city2 and city1-city3. Then if city1 is occupied by the enemy, we must have 1 highway repaired, that is the highway city2-city3.
Input Specification:
Each input file contains one test case. Each case starts with a line containing 3 numbers N (<1000), M and K, which are the total number of cities, the number of remaining highways, and the number of cities to be checked, respectively. Then M lines follow, each describes a highway by 2 integers, which are the numbers of the cities the highway connects. The cities are numbered from 1 to N. Finally there is a line containing K numbers, which represent the cities we concern.
Output Specification:
For each of the K cities, output in a line the number of highways need to be repaired if that city is lost.
Sample Input:
3 2 3
1 2
1 3
1 2 3
Sample Output:
1
0
0
题目分析
不是很难,有关图的问题,除去被破坏的城市后,有多少个连通图就要修多少条路,代码如下。
具体代码
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 1005int N, M, K;
int road[MAXSIZE][MAXSIZE];
int is_visited[MAXSIZE];void DFS(int n)
{
is_visited[n] = 1;
for (int i = 1; i一点想说的话
今天真是太痛苦了,这几天坚持每天两道题,如果能A掉自然很好,但是如果A不掉就觉得很痛苦,每次都感觉自己有思路,但是总是在细节上出问题,看别人的代码也觉得自己和他们的思路是一样的,为什么我的不对呢???有的时候能找到bug有的时候找不到真的非常非常痛苦。
其实今天是写了两道题的,但是第二道真的没写出来,别人的代码思路明明和我一样,样例我也过了,可是就是A不了,一开始总是安慰自己C语言刷难度大一点,可是看了一个大佬的C实现代码,愈加觉得自己是纯粹的菜,跟语言没关系,所以心态有点炸。
我觉得我需要调整一下,顺便趁着这几天把C++学完,所以之后几天每天刷一题。PTA A1013的更多相关文章
- 浙大PTA - - 堆中的路径
题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21731 本题即考察最小堆的基本操作: #include "iostrea ...
- 浙大PTA - - File Transfer
题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21732 #include "iostream" #includ ...
- ERROR<53761> - Plugins - conn=-1 op=-1 msgId=-1 - Connection Bind through PTA failed (91). Retrying...
LDAP6.3在DSCC控制台启动实例完成,但是操作状态显示“意外错误”,查看日志如下: 04/May/2016:21:10:39 +0800] - Sun-Java(tm)-System-Direc ...
- PTA中提交Java程序的一些套路
201708新版改版说明 PTA与2017年8月已升级成新版,域名改为https://pintia.cn/,官方建议使用Firefox与Chrome浏览器. 旧版 PTA 用户首次在新版系统登录时,请 ...
- PTA分享码-Java
主要用于Java语法练习,非竞赛类题目. 1. Java入门 959dbf0b7729daa61d379ec95fb8ddb0 2. Java基本语法 23bd8870e ...
- C语言第一次实验报告————PTA实验1.2.3内容
一.PTA实验作业 题目1.温度转换 本题要求编写程序,计算华氏温度100°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代 ...
- PTA题---求两个有序序列中位数所体现的思想。
---恢复内容开始--- 近日,在做PTA题目时,遇到了一个这样的题,困扰了很久.题目如下:已知有两个等长的非降序序列S1, S2, 设计函数求S1与S2并集的中位数.有序序列A0,A1, ...
- 第十四,十五周PTA作业
1.第十四周part1 7-3 #include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; ...
- 第七周PTA作业
第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...
随机推荐
- Python 參考網站
Python 3 Readiness : http://py3readiness.org/ Python Speed Center : https://speed.python.org/ Python ...
- RN 性能优化
按需加载: 导出模块使用属性getter动态require 使用Import语句导入模块,会自动执行所加载的模块.如果你有一个公共组件供业务方使用,例如:common.js import A from ...
- com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: con ...
- Visual Studio 2019 远程调试工具(Remote Debugger)使用方法
目录 0.Visual Studio 2019 远程调试工具使用场景 1.Visual Studio 2019 远程调试工具下载地址: 2.Visual Studio 2019 远程调试工具-安装及运 ...
- Java IO体系之File类浅析
Java IO体系之File类浅析 一.File类介绍 位于java.io下的Java File类以抽象的方式代表文件名和目录路径名.该类主要用于文件和目录的创建.文件的查找和文件的删除等.File对 ...
- Leetcode之深度优先搜索(DFS)专题-301. 删除无效的括号(Remove Invalid Parentheses)
Leetcode之深度优先搜索(DFS)专题-301. 删除无效的括号(Remove Invalid Parentheses) 删除最小数量的无效括号,使得输入的字符串有效,返回所有可能的结果. 说明 ...
- 百度地图小Demo---获取当前地址以及拖拽显示地址
1.效果图 2.源码 主要使用百度地图的JavaScript API文件,以及一个JQuery文件. <!doctype html> <html lang="en" ...
- Nginx入门(一):在centos上安装nginx
CenterOS7安装Nginx =================== 参考:https://www.xuliangwei.com/bgx/972.html nginx官网下载地址:http://n ...
- POJ-1325 Machine Schedule 二分图匹配 最小点覆盖问题
POJ-1325 题意: 有两台机器A,B,分别有n,m种模式,初始都在0模式,现在有k项任务,每项任务要求A或者B调到对应的模式才能完成.问最少要给机器A,B调多少次模式可以完成任务. 思路: 相当 ...
- Educational Codeforces Round 48 D Vasya And The Matrix
EDU #48 D 题意:给定一个矩阵,已知每一行和每一列上数字的异或和,问矩阵上的数字是多少,不存在则输出NO. 思路:构造题,可以考虑只填最后一行,和最后一列,其中(n,m)要特判一下.其他格子给 ...