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      2017.01.16 23:41

POJ1637.Sightseeing tour(观光旅游线)——混合图的欧拉回路
http://poj.org/problem?id=1637转自kuangbin巨巨 http://www.cnblogs.com/kuangbin/p/3537525.html一个混合图，既含无向边又含有向边 对无向边任取一个方向，将混合图变为有向图，转变为有向图后，根据有向图欧拉通路/回路的充要条件，进行判断 1.有向图是欧拉图当且仅当是强连通的且每个顶点的入度等于出度 2.有向图是半欧
POJ1637 Sightseeing tour（混合欧拉图的判断）

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

POJ1637 Sightseeing tour 网络流

POJ-1637 Sightseeing tour

poj 1637 Sightseeing tour

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 题解