HDU 3478 邻接表 hash表 图论
来源:互联网 发布:unity3d 官网 编辑:程序博客网 时间:2024/05/13 07:10
Catch
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1570 Accepted Submission(s): 753
Problem Description
A thief is running away!
We can consider the city where he locates as an undirected graph in which nodes stand for crosses and edges stand for streets. The crosses are labeled from 0 to N–1.
The tricky thief starts his escaping from cross S. Each moment he moves to an adjacent cross. More exactly, assume he is at cross u at the moment t. He may appear at cross v at moment t + 1 if and only if there is a street between cross u and cross v. Notice that he may not stay at the same cross in two consecutive moment.
The cops want to know if there’s some moment at which it’s possible for the thief to appear at any cross in the city.
We can consider the city where he locates as an undirected graph in which nodes stand for crosses and edges stand for streets. The crosses are labeled from 0 to N–1.
The tricky thief starts his escaping from cross S. Each moment he moves to an adjacent cross. More exactly, assume he is at cross u at the moment t. He may appear at cross v at moment t + 1 if and only if there is a street between cross u and cross v. Notice that he may not stay at the same cross in two consecutive moment.
The cops want to know if there’s some moment at which it’s possible for the thief to appear at any cross in the city.
Input
The input contains multiple test cases:
In the first line of the input there’s an integer T which is the number of test cases. Then the description of T test cases will be given.
For any test case, the first line contains three integers N (≤ 100 000), M (≤ 500 000), and S. N is the number of crosses. M is the number of streets and S is the index of the cross where the thief starts his escaping.
For the next M lines, there will be 2 integers u and v in each line (0 ≤ u, v < N). It means there’s an undirected street between cross u and cross v.
In the first line of the input there’s an integer T which is the number of test cases. Then the description of T test cases will be given.
For any test case, the first line contains three integers N (≤ 100 000), M (≤ 500 000), and S. N is the number of crosses. M is the number of streets and S is the index of the cross where the thief starts his escaping.
For the next M lines, there will be 2 integers u and v in each line (0 ≤ u, v < N). It means there’s an undirected street between cross u and cross v.
Output
For each test case, output one line to tell if there’s a moment that it’s possible for the thief to appear at any cross. Look at the sample output for output format.
Sample Input
23 3 00 10 21 22 1 00 1
Sample Output
Case 1: YESCase 2: NOHintFor the first case, just look at the table below. (YES means the thief may appear at the cross at that moment)For the second input, at any moment, there’s at least one cross that the thief can’t reach.
题目大意:
一个贼要逃跑,每过一天换一个城市,不能在一个城市中停留。问,贼有没有可能同时出现在所有的城市。
遇到的问题和思路:
刚开始想要100000^2的数组,然后肯定是太大了,memory不够。然后是打算用并查集的方法去做,看看能不能形成环,能形成环就一定能够遍历,但是这个的做法如果遇到了连续输入两次相同的值就行不通了,所以要加一个判断的数组,所以又回到了原来的数组上去了。于是看了一下别人的题解:判断能否在奇数步和偶数步的时候同时到达所有的点。然后就做出来了。
给出代码:
0 0
- HDU 3478 邻接表 hash表 图论
- 邻接表vector HDU 3478 catch
- HDU-2544(SPFA()邻接表)
- HDU-2647-邻接表模板
- hash 链地址法+ 数组模拟邻接表实现
- URAL 1486 Equal Squares 二维字符串Hash + 邻接表分组
- nyoj--138--找球号(二)(hash+邻接表)
- hdu 2586 How far away ? 【图论-邻接表-图转树-Lca】
- hdu 2544 最短路 (邻接表)
- HDU 2923 Einbahnstrasse(邻接表+dijkstra)
- HDU-1874(邻接表写Dijkstra())
- HDU 2544 最短路(spfa邻接表)
- hdu 4707 Pet(图 + 邻接表)
- 【SPFA邻接表】HDU 1535 Invitation Cards
- HDU 4707--Pet【DFS && 邻接表】
- HDU 2647( 拓扑+邻接表)
- hdu 4707 Pet(DFS && 邻接表)
- hdu 1285 邻接表数组实现
- poj_2250 Compromise(输出最长公共子序列)
- NodeJS Connect 简单错误处理中间件
- Hibernate【2】(用Hibernate Tools生成Hibernate Mapping映射文件)
- C#回顾
- 接口类interface概述
- HDU 3478 邻接表 hash表 图论
- Nginx配置文件详细说明
- R语言︱常用统计方法包+机器学习包(名称、简介)
- gdbx线程感知(OS Aware)调试使用说明
- 计算机图形学入门教程OpenGL版.第0篇.前言
- HDU1247 Hat’s Words (字典树)
- 纯UGUI项目的开发工作流及发布
- bzoj2298 problem a 动态规划
- C#成神之路<17> C#使用磁盘数据文件(1)