-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCQUOJ 21461
98 lines (88 loc) · 1.51 KB
/
CQUOJ 21461
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <bits/stdc++.h>
#define ll long long
#define N 100000*2+5
using namespace std;
int in[N];
int head[N],tot;
struct nodes
{
int to,next;
} Edge[N];
void add(int u,int v)
{
Edge[tot].to = v;
Edge[tot].next = head[u];
head[u] = tot++;
}
void init()
{
memset(head,-1,sizeof(head));
tot = 0;
}
map<ll,int>hashs;
void solve()
{
queue<int>tmp;
hashs.clear();
int n,m,l = 0;
init();
memset(in,0,sizeof(in));
scanf("%d %d",&n,&m);
for(int i = 0; i < m; i++)
{
ll u,v;
scanf("%lld %lld",&u,&v);
if(hashs[u] == 0)
{
hashs[u] = ++l;
}
u = hashs[u];
if(hashs[v] == 0)
{
hashs[v] = ++l;
}
v = hashs[v];
add(u,v);
in[v]++;
}
for(int i = 1; i <= l; i++)
{
if(in[i] == 0)
tmp.push(i);
}
while(!tmp.empty())
{
int cur = tmp.front();
tmp.pop();
for(int i = head[cur]; i != -1; i = Edge[i].next)
{
int to = Edge[i].to;
in[to]--;
if(in[to] == 0)
tmp.push(to);
}
}
bool ans = true;
for(int i = 1; i <= l; i++)
{
if(in[i] != 0)
{
ans = false;
break;
}
}
if(ans)
printf("No\n");
else
printf("Yes\n");
}
int main(void)
{
int t,cnt = 0;
scanf("%d",&t);
while(t--)
{
//printf("Case #%d:\n",++cnt);
solve();
}
}