-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpt07y1.cpp
More file actions
46 lines (42 loc) · 744 Bytes
/
pt07y1.cpp
File metadata and controls
46 lines (42 loc) · 744 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
int in[20003],out[20003],parent[10003];
int find(int i) {
if(parent[i]==0)
return i;
return find(parent[i]);
}
void Union(int a,int b) {
int aset=find(a);
int bset=find(b);
parent[aset]=bset;
}
bool isCycle(int m) {
for(int i=0;i<m;i++) {
int a=find(in[i]);
int b=find(out[i]);
if(a==b)
return true;
Union(a,b);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++) {
cin>>in[i]>>out[i];
}
if(isCycle(m))
cout<<"NO\n";
else
cout<<"YES\n";
return 0;
}