#P2416. 泡芙

泡芙

Description

After much effort, the Martian Cat finally reaches Pluto. There are NN cities and MM undirected edges. The Martian Cat plans to visit the Pluto Rabbit and has heard that some cream puffs have fallen on certain edges, so he wants to collect some as a gift. However, the Martian Cat’s aura conflicts with Pluto: once he traverses an edge, that edge can no longer be used. If the Pluto Rabbit cannot get any cream puffs, they won’t be happy. Given the positions of the Martian Cat and the Pluto Rabbit, determine whether the Pluto Rabbit can get a cream puff, i.e., whether there exists a trail from SS to TT that passes through at least one edge with a cream puff.

Input Format

The first line contains N,MN, M, the number of vertices and edges.

Each of the next MM lines contains X,Y,ZX, Y, Z, indicating an undirected edge between XX and YY; Z=1Z = 1 means there is a cream puff on this edge, and Z=0Z = 0 means there is not.

The next line contains QQ, the number of queries.

Each of the following QQ lines contains S,TS, T, the positions of the Martian Cat and the Pluto Rabbit.

Output Format

For each query, output YES or NO.

6 7
1 2 0
2 3 0
3 1 0
3 4 1
4 5 0
5 6 0
6 4 0
1
1 6
YES

Hint

Test point ID NN \le MM \le QQ \le Special property
141 \sim 4 10001000 N1N - 1 5×1045 \times 10^4 The graph is a tree.
585 \sim 8 3×1053 \times 10^5 3×1053 \times 10^5 None
9109 \sim 10 2020 5050 55
111411 \sim 14 10001000 50005000 5×1045 \times 10^4
152015 \sim 20 3×1053 \times 10^5

The graph is connected.

Translated by ChatGPT 5