forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
60 lines (45 loc) · 1.2 KB
/
A.cpp
File metadata and controls
60 lines (45 loc) · 1.2 KB
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
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vii;
int A[5007];
bool adj[5007][5007];
vii adList;
bool check(int u, int v) {
for(int i=1; i<adList[u].size(); i++) {
int k = adList[u][i];
if (!adj[k][v]) return false;
}
return true;
}
int main() {
freopen("bombing.in", "r", stdin);
freopen("bombing.out", "w", stdout);
int n, m, x, y, u, v;
scanf("%d %d", &n, &m);
bool res = true;
for(int i=1; i<=n; i++) {
scanf("%d", &x);
A[x] = i;
}
adList.assign(n+1, vi());
for(int i=1; i<=m; i++) {
scanf("%d %d", &x, &y);
u = A[x]; v = A[y];
adj[u][v] = adj[v][u] = true;
if (u < v) adList[u].push_back(v);
else adList[v].push_back(u);
}
for(int i=1; i<=n; i++) {
sort(adList[i].begin(), adList[i].end());
}
for(int i=1; i<n; i++) {
if (adList[i].size() > 0) {
u = adList[i][0];
res = check(i, u);
}
if (!res) break;
}
if (res) cout << "YES" << endl;
else cout << "NO" << endl;
}