# YZOJ P2872 [POJ 1637]Sightseeing tour

Time Limit：1000MS      Memory Limit：131072KB

Difficulty: $$6.0$$

• ### 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 \leq m \leq 200$$, $$1 \leq s \leq 1000$$ being the number of junctions and streets, respectively. The following s lines contain the streets. Each street is described with three integers, $$x_i$$, $$y_i$$, and $$d_i$$, $$1 \leq x_i,y_i \leq m$$, $$0 \leq d_i \leq 1$$, where $$x_i$$ and $$y_i$$ are the junctions connected by a street. If $$d_i=1$$, then the street is a one-way street (going from $$x_i$$ to $$y_i$$), 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.

Source: POJ 1637