POJ 1637 Sightseeing tour
2015-09-29 14:49
423 查看
Sightseeing tour
Description
The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beautiful city. They want to construct the tour so that every street in the city is visited exactly once. The bus should also
start and end at the same junction. As in any city, the streets are either one-way or two-way, traffic rules that must be obeyed by the tour bus. Help the executive board and determine if it's possible to construct a sightseeing tour under these constraints.
Input
On the first line of the input is a single positive integer n, telling the number of test scenarios to follow. Each scenario begins with a line containing two positive integers m and s, 1 <= m <= 200,1 <= s <= 1000 being the number of junctions and streets,
respectively. The following s lines contain the streets. Each street is described with three integers, xi, yi, and di, 1 <= xi,yi <= m, 0 <= di <= 1, where xi and yi are the junctions connected by a street. If di=1, then the street is a one-way street (going
from xi to yi), otherwise it's a two-way street. You may assume that there exists a junction from where all other junctions can be reached.
Output
For each scenario, output one line containing the text "possible" or "impossible", whether or not it's possible to construct a sightseeing tour.
混合图欧拉回路的判定:
做的第一道关于网络流的题目,首先是结合欧拉回路所需的一些要求构图,网络流只需要用到无向边(流网络动态改变,只有无向边方向要确定要调整)...
因为自己在写增广路算法的时候的一点点小问题,这道题目调试了2天,浪费了大把时间,以后要更注意细节。
另外学到了欧拉回路的构造算法---fleury算法,这是一大收获:
create a stack s and push a vertex at the graph;
fleury()
{
where (!s.empty())
{
int u = s.top();
s.pop();
if(u have out edge)
dfs(u);
else
path[cnt++] = u;
}
}
dfs(int u)
{
s.push(u);
while(u have out edge)
{
let v = the vertex adjacent with u;
delete this edge;
s.push(u = v);
}
}
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8362 | Accepted: 3530 |
The city executive board in Lund wants to construct a sightseeing tour by bus in Lund, so that tourists can see every corner of the beautiful city. They want to construct the tour so that every street in the city is visited exactly once. The bus should also
start and end at the same junction. As in any city, the streets are either one-way or two-way, traffic rules that must be obeyed by the tour bus. Help the executive board and determine if it's possible to construct a sightseeing tour under these constraints.
Input
On the first line of the input is a single positive integer n, telling the number of test scenarios to follow. Each scenario begins with a line containing two positive integers m and s, 1 <= m <= 200,1 <= s <= 1000 being the number of junctions and streets,
respectively. The following s lines contain the streets. Each street is described with three integers, xi, yi, and di, 1 <= xi,yi <= m, 0 <= di <= 1, where xi and yi are the junctions connected by a street. If di=1, then the street is a one-way street (going
from xi to yi), otherwise it's a two-way street. You may assume that there exists a junction from where all other junctions can be reached.
Output
For each scenario, output one line containing the text "possible" or "impossible", whether or not it's possible to construct a sightseeing tour.
混合图欧拉回路的判定:
做的第一道关于网络流的题目,首先是结合欧拉回路所需的一些要求构图,网络流只需要用到无向边(流网络动态改变,只有无向边方向要确定要调整)...
因为自己在写增广路算法的时候的一点点小问题,这道题目调试了2天,浪费了大把时间,以后要更注意细节。
另外学到了欧拉回路的构造算法---fleury算法,这是一大收获:
create a stack s and push a vertex at the graph;
fleury()
{
where (!s.empty())
{
int u = s.top();
s.pop();
if(u have out edge)
dfs(u);
else
path[cnt++] = u;
}
}
dfs(int u)
{
s.push(u);
while(u have out edge)
{
let v = the vertex adjacent with u;
delete this edge;
s.push(u = v);
}
}
相关文章推荐
- JavaScript数据结构和算法之图和图算法
- Poj2638 网络流+最短路+二分答案
- BZOJ3275 Number (最小割)
- [笔记] 网络流-最大流 POJ-1273\HDU-4240
- 上下界网络流初探
- Edmonds-Karp 最大流 hdu 1532 Drained Ditches
- 网络流_poj1273
- POJ 1273 Drainage Ditches 最大流 dinic
- POJ1273-Drainage Ditches
- 【网络流】复杂的大门
- ACM/ICPC World Finals 2013 C Surely You Congest
- 网络流算法整理
- [BZOJ1797][AHOI2009][最大流][强连通分量]Mincut最小割
- [BZOJ2324][ZJOI2011][最小费用最大流]营救皮卡丘
- [BZOJ1834][ZJOI2010][最大流][最小费用最大流]网络扩容
- Topcoder SRM642 TaroCutting
- POJ2391解题报告
- uva 11248
- [网络流24题 #2]太空飞行计划问题
- [网络流24题 #18]分配问题