2 shunfurh shunfurh 于 2017.01.16 23:22 提问

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.
Sample Input

4
5 8
2 1 0
1 3 0
4 1 1
1 5 0
5 4 1
3 4 0
4 2 1
2 2 0
4 4
1 2 1
2 3 0
3 4 0
1 4 1
3 3
1 2 0
2 3 0
3 2 0
3 4
1 2 0
2 3 1
1 2 0
3 2 0
Sample Output

possible
impossible
impossible
possible

1个回答

caozhy
caozhy   Ds   Rxr 2017.01.16 23:41
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
POJ1637.Sightseeing tour(观光旅游线)——混合图的欧拉回路
http://poj.org/problem?id=1637转自kuangbin巨巨 http://www.cnblogs.com/kuangbin/p/3537525.html一个混合图,既含无向边又含有向边 对无向边任取一个方向,将混合图变为有向图,转变为有向图后,根据有向图欧拉通路/回路的充要条件,进行判断 1.有向图是欧拉图当且仅当是强连通的且每个顶点的入度等于出度 2.有向图是半欧
POJ1637 Sightseeing tour(混合欧拉图的判断)
给出一张混合图(有有向边,也有无向边),判断是否存在欧拉回路。 首先是对图中的无向边随意定一个方向,然后统计每个点的入度(indeg)和出度(outdeg),如果(indeg - outdeg)是奇数的话,一定不存在欧拉回路; 如果所有点的入度和出度之差都是偶数,那么就开始网
Sightseeing tour
Sightseeing tour Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8276 Accepted: 3489Description The city executive board in Lund wants to construct a sightseeing tour by bus in L
poj1734 - Sightseeing trip
想看更多的解题报告: http://blog.csdn.net/wangjian8006/article/details/7870410                                   转载请注明出处:http://blog.csdn.net/wangjian8006 题目大意:给出你一个无向图,要你求一个最小环,最小环的最少有3个节点,如果有环则顺序输出节点上的点,如
POJ1637 Sightseeing tour 网络流
题目中既有有向边又有五项边
POJ-1637 Sightseeing tour
题目大意: 给你m个点,有s条边,这s条边有的是有向边(di = 1),有的是无向边(di = 0),问你这个图是否存在欧拉回路。 解题思路: 我是看着这个题解写出来这道题目的。链接在这里 把这个混合图先当作是有向图,每个输入xi,yi,di不管di为0或1,均当作是从xi到yi的有向边(无向边可任意设置方向),然后记录入度和出度的差值,如果差值为奇数则必然不可能存在欧拉回路。剩下的部分可
poj 1637 Sightseeing tour
题意:给出一个混合图(有的边有向,有的边无向),问此图是否存在欧拉回路。 先说说欧拉回路吧,起点和终点相同,经过图G的每条边一次,且只经过一次的路径称为欧拉回路。 按照图的不同分为:无向图欧拉回路、有向图欧拉回路和混合图欧拉回路。 判断一个图是否存在欧拉回路: 1.无向图:图连通,且图中均为偶度顶点。 2.有向图:图连通,且图中所有顶点出入度相等。 3.混合图:混合图欧拉回路的
洛谷 P2868 [USACO07DEC]观光奶牛Sightseeing Cows 01分数规划
题目描述Farmer John has decided to reward his cows for their hard work by taking them on a tour of the big city! The cows must decide how best to spend their free time.Fortunately, they have a detailed cit
AtCoder Grand Contest 018 E - Sightseeing Plan
Problem Statement Joisino is planning on touring Takahashi Town. The town is divided into square sections by north-south and east-west lines. We will refer to the section that is the x-th from the
POJ1637: Sightseeing tour 题解
感觉这个网络流的建图还是很妙的 欧拉回路的判定肯定是所有点的入度=出度 我们考虑刚开始随意给无向边定向,这样算出每个点的入度和出度 我们改变一条有向边的方向,会使某个点度数+2,某个点度数-2,所以点的度数的奇偶性不变 我们考虑这样建图:按照我们刚开始给无向边定的向反向连边,容量为1,对于d&amp;gt;0的点i,从s向i连流量为d/2的边,对于d&amp;lt;0的点i,从i向t连流量为-d/2的边,...