8660: Winner Prediction

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

A tournament consisting of n participants is currently taking place. The players are numbered from 1 to n. Every match is between two participants, and there are no draws. The participant who wins the most matches wins the entire tournament; if there are multiple participants tied at the first place, all of them win the tournament.

At the current state, some matches have ended, and others are yet to start. You are given the results of all ended matches. Write a program to determine whether it is possible for player 1 to win the tournament.

You are given T independent test cases. Solve each of them.

输入格式

 

The first line of input consists of a single integer T(1T100), indicating the number of test cases. Then TT test cases follow.

Each of the T test cases consists of multiple lines.

The first line contains three integers n,m1,m2(1n500,1m1,m21000), indicating the number of participants, the number of ended matches and the number of upcoming matches.

Each of the next m1 lines contains three space-separated integers x,y,z(1x,yn,x=y,0z1), indicating an ended match between player xx and player y , z = 1 means player xx won the match and z=0 means player y won the match.

Each of the next m_2m2 lines contains two space-separated integers x,y(1x,yn,x=y), indicating an upcoming match between player xx and player yy.

输出格式

For each test case, if it is possible of player 1 to win the tournament, print a line YES; otherwise print a line \texttt{NO}NO.

输入样例 复制

2
4 2 1
2 3 1
3 2 1
1 4
4 2 2
2 3 1
2 4 1
1 2
3 4

输出样例 复制

YES
NO