第七天

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

题目分析

不是很难,有关图的问题,除去被破坏的城市后,有多少个连通图就要修多少条路,代码如下。

具体代码

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define MAXSIZE 1005

  4. int N, M, K;

  5. int road[MAXSIZE][MAXSIZE];

  6. int is_visited[MAXSIZE];

  7. void DFS(int n)

  8. {

  9. is_visited[n] = 1;

  10. for (int i = 1; i

  11. 一点想说的话

  12. 今天真是太痛苦了,这几天坚持每天两道题,如果能A掉自然很好,但是如果A不掉就觉得很痛苦,每次都感觉自己有思路,但是总是在细节上出问题,看别人的代码也觉得自己和他们的思路是一样的,为什么我的不对呢???有的时候能找到bug有的时候找不到真的非常非常痛苦。

  13. 其实今天是写了两道题的,但是第二道真的没写出来,别人的代码思路明明和我一样,样例我也过了,可是就是A不了,一开始总是安慰自己C语言刷难度大一点,可是看了一个大佬的C实现代码,愈加觉得自己是纯粹的菜,跟语言没关系,所以心态有点炸。

  14. 我觉得我需要调整一下,顺便趁着这几天把C++学完,所以之后几天每天刷一题。

  15. PTA A1013的更多相关文章

      1. 浙大PTA - - 堆中的路径
      1. 题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21731 本题即考察最小堆的基本操作: #include "iostrea ...

      1. 浙大PTA - - File Transfer
      1. 题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21732 #include "iostream" #includ ...

      1. ERROR<53761> - Plugins - conn=-1 op=-1 msgId=-1 - Connection Bind through PTA failed (91). Retrying...
      1. LDAP6.3DSCC控制台启动实例完成,但是操作状态显示“意外错误”,查看日志如下: 04/May/2016:21:10:39 +0800] - Sun-Java(tm)-System-Direc ...

      1. PTA中提交Java程序的一些套路
      1. 201708新版改版说明 PTA20178月已升级成新版,域名改为https://pintia.cn/,官方建议使用Firefox与Chrome浏览器. 旧版 PTA 用户首次在新版系统登录时,请 ...

      1. PTA分享码-Java
      1. 主要用于Java语法练习,非竞赛类题目.   1. Java入门          959dbf0b7729daa61d379ec95fb8ddb0   2. Java基本语法   23bd8870e ...

      1. C语言第一次实验报告————PTA实验1.2.3内容
      1. 一.PTA实验作业 题目1.温度转换 本题要求编写程序,计算华氏温度100°F对应的摄氏温度.计算公式:C=5×(F32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代 ...

      1. PTA题---求两个有序序列中位数所体现的思想。
      1. ---恢复内容开始--- 近日,在做PTA题目时,遇到了一个这样的题,困扰了很久.题目如下:已知有两个等长的非降序序列S1, S2, 设计函数求S1S2并集的中位数.有序序列A0​​,A1​​, ...

      1. 第十四,十五周PTA作业
      1. 1.第十四周part1 7-3 #include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; ...

      1. 第七周PTA作业
      1. 第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...

    1.  
    2. 随机推荐

        1. springboot整合solr
        1. 上一篇博客中简要写了solrwindows的安装与配置,这一篇接上文写一下springboot整合solr,代码已经上传到github,传送门. 1.新建core并配置schema 上篇博客中已经有 ...

        1. [Spring cloud 一步步实现广告系统] 21. 系统错误汇总
        1. 广告系统学习过程中问题答疑 博客园 Eureka集群启动报错 Answer 因为Eureka在集群启动过程中,会连接集群中其他的机器进行数据同步,在这个过程中,如果别的服务还没有启动完成,就会出现Co ...

        1. ansible之数据提取与Juniper实例演示
        1. 一.Ansible列表两种表达方式 基于YAML的列表 my_list: - a - b - c - d 基于Json格式的列表 {"my_list":[ "a" ...

        1. Hive 系列(六)—— Hive 视图和索引
        1. 一.视图 1.1 简介 Hive 中的视图和 RDBMS 中视图的概念一致,都是一组数据的逻辑表示,本质上就是一条 SELECT 语句的结果集.视图是纯粹的逻辑对象,没有关联的存储 (Hive 3.0 ...

        1. egret项目发布为微信小程序
        1. 1.更改游戏的缩放模式 因为微信小游戏不支持showAll,如果你使用了showAll模式.可以改成fixedWidthfixedHeight.在index.html里修改,如下图 但这个又涉及到了 ...

        1. HBase 系列(四)—— HBase 集群环境配置
        1. 一.集群规划 这里搭建一个 3 节点的 HBase 集群,其中三台主机上均为 Regin Server.同时为了保证高可用,除了在 hadoop001 上部署主 Master 服务外,还在 hadoo ...

        1. 数据读写API——IO
        1. 理清一些概念 1.Java 中的IO是干啥的? IO指的是InputOutput,主要目的是实现数据在存储介质之间的传输.[流:数据流,类比与水流的流动] 2.IO分类 按照操作单元来划分,可以分为 ...

        1. sql server中的cte
        1. SQL Server 2005开始,提供了CTE(Common Table Expression,公用表表达式)的语法支持. CTE是定义在SELECT.INSERT.UPDATEDELETE语句 ...

        1. tf.control_dependencies
        1. tf.control_dependencies()是用来控制计算流图的,给图中的某些节点指定计算的顺序. 原型: tf.control_dependencies(self, control_input ...

        1. [系列] - go-gin-api 路由中间件 - 日志记录(三)
        1. 目录 概述 gin.Logger() 自定义 Logger() 源码地址 go-gin-api 系列文章 概述 首先同步下项目概况: 上篇文章分享了,规划项目目录和参数验证,其中参数验证使用的是 va ...