Codeforces 27B Tournament(dfs,判断有向图中点的连通性)
2016-03-18 22:36
447 查看
Tournament
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each
of them is a match between two participants. n·(n - 1) / 2 games were played during the tournament, and each participant had a match with each other participant.
The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «xiyi»,
where xi and yi are the numbers of participants. The
first number in each pair is a winner (i.e. xi is a winner and yi is
a loser). There is no draws.
Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value pj — the speed of falling asleep. The person
who has lower speed wins. Every person has its own value pj, constant during the life.
It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game.
Input
The first line contains one integer n (3 ≤ n ≤ 50) — the number of participants. The following n·(n - 1) / 2 - 1 lines
contain the results of the games. Each game is described in a single line by two integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi),
where xi и yi are the numbers of the opponents in this
game. It is known that during the tournament each of the n participants played n - 1 games, one game with each other participant.
Output
Output two integers x and y — the missing record. If there are several solutions, output any of them.
Sample Input
Input
Output
题意:给出一个完全竞赛图,去掉一条边,让你求出这条边。
思路:先不考虑这条边的方向,求出这条边的两个顶点(u,v),然后从其中一个顶点u深搜,看能否连通道另一个顶点v,如果可以,输出顺序为 u,v。否则相反。
代码如下:
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each
of them is a match between two participants. n·(n - 1) / 2 games were played during the tournament, and each participant had a match with each other participant.
The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «xiyi»,
where xi and yi are the numbers of participants. The
first number in each pair is a winner (i.e. xi is a winner and yi is
a loser). There is no draws.
Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value pj — the speed of falling asleep. The person
who has lower speed wins. Every person has its own value pj, constant during the life.
It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game.
Input
The first line contains one integer n (3 ≤ n ≤ 50) — the number of participants. The following n·(n - 1) / 2 - 1 lines
contain the results of the games. Each game is described in a single line by two integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi),
where xi и yi are the numbers of the opponents in this
game. It is known that during the tournament each of the n participants played n - 1 games, one game with each other participant.
Output
Output two integers x and y — the missing record. If there are several solutions, output any of them.
Sample Input
Input
4 4 2 4 1 2 3 2 1 3 1
Output
4 3
题意:给出一个完全竞赛图,去掉一条边,让你求出这条边。
思路:先不考虑这条边的方向,求出这条边的两个顶点(u,v),然后从其中一个顶点u深搜,看能否连通道另一个顶点v,如果可以,输出顺序为 u,v。否则相反。
代码如下:
相关文章推荐
- 渗透技术一瞥(图)
- 图片引发的溢出危机(图)
- C++实现图的邻接矩阵存储和广度、深度优先遍历实例分析
- C++实现图的邻接表存储和广度优先遍历实例分析
- jQuery圆形统计图开发实例
- Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
- 手机短信轰炸(图)
- C语言实现图的遍历之深度优先搜索实例
- python数据结构之图的实现方法
- ASP.Net页面生成饼图实例
- 基于Java实现的图的广度优先遍历算法
- win2003分布式文件系统(dfs)配置方法[图文详解]
- win2003分布式文件系统及其部署 图文教程
- Hadoop2.6+jdk8的安装部署(1)——使用jar包安装部署【详细】
- RelativeLayout浅谈
- 图
- Hadoop FS Shell
- DFS使用方法总结
- Ext Scheduler Web资源甘特图控件
- 键盘码 图