-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path327-d.cpp
More file actions
50 lines (49 loc) · 954 Bytes
/
327-d.cpp
File metadata and controls
50 lines (49 loc) · 954 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
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int n, m;
int getfather(vector<int> &set, int x)
{
if (x == set[x])
return x;
else
return set[x]=getfather(set, set[x]);
}
void merge(vector<int> &set,int x,int y)
{
x=getfather(set,x);
y=getfather(set,y);
set[y]=x;
}
int main()
{
cin >> n >> m;
vector<int> set(2 * n + 1);
for (int i = 1; i <= 2 * n; i++)
{
set[i] = i;
}
bool flag = 0;
vector<int> a(m + 1), b(m + 1);
for (int i = 1; i <= m; i++)
{
cin >> a[i];
}
for (int i = 1; i <= m; i++)
{
cin >> b[i];
}
for (int i = 1; i <= m; i++)
{
if (getfather(set,a[i]) == getfather(set,b[i]))
{
cout << "No" << endl;
system("pause");
return 0;
}
merge(set,a[i],b[i]+n);
merge(set,b[i],a[i]+n);
}
cout << "Yes" << endl;
system("pause");
return 0;
}