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 ...
随机推荐
- LoRaWAN Server开源项目部署
1,安装MQTT broker,Redis,PostgreSQL sudo apt install mosquitto mosquitto-clients redis-server redis-too ...
- 基础部分之System、Object、Calendar、StringBuffer
System.out.println(obj)和 System.out.println(obj.toString())区别 public static void main(String[] args) ...
- pringboot pom文件引入本地jar包和对其打jar包
maven引入本地jar包需要在pom文件中天剑如下配置: <dependency> <groupId>com.baidu</groupId> <artifa ...
- springcloud(九):熔断器Hystrix和Feign的全套应用案例(二)
一.. 创建Eureka-Server 服务中心项目 1. 创建Eureka-Server 服务中心项目架构如下 2. pom.xml <dependencies> <depende ...
- CRNN+CTC (基于CTPN 的end-to-end OCR)
1. https://zhuanlan.zhihu.com/p/43534801 (详细原理) 2. https://blog.csdn.net/forest_world/article/detai ...
- Docker学习总结(六)--Dockerfile
什么是 Dockerfile Dockerfile 是由一系列命令和参数构成的脚本,这些命令应用于基础镜像并最终创建一个新的镜像. 对于开发人员:可以为开发团队提供一个完全一致的开发环境; 对于测试人 ...
- C# Mqtt 断线重连
在通过 MqttClient 客户端连接之后,在服务端服务重启时,客户端如果没有重连机制,则无法再接收到订阅的消息. 使用的 Mqtt 组件为:M2Mqtt.Net.dll 一些特性发现 (1)如果提 ...
- 面试必备:常考Java基础知识总结(持续更新)
面试必备:常考Java基础知识总结(持续更新) 本文的Java方面基础知识是我在面试过程中的积累和总结. Java基本数据类型.所占空间大小及对应包装类 基本类型 大小 包装类 boolean - B ...
- Windows GIT SSH 免密教程
Windows GIT SSH 免密教程 安装git客户端,最新下载地址如下 https://github.com/git-for-windows/git/releases/download/v2.2 ...
- ThreadLocal可以解决并发问题吗?
前言 到底什么是线程的不安全?为什么会存在线程的不安全?线程的不安全其实就是多个线程并发的去操作同一共享变量没用做同步所产生意料之外的结果.那是如何体现出来的呢?我们看下面的一个非常经典的例子:两个操 ...