-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT1.cpp
More file actions
35 lines (32 loc) · 705 Bytes
/
Copy pathT1.cpp
File metadata and controls
35 lines (32 loc) · 705 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
#include <iostream>
#include <set>
using namespace std;
const int MAXN = 1e5+1;
set<int> adj[MAXN];
int a[MAXN];
int last = 1;
bool dfs(int v,int n){
if(last > n) return true;
while(last <= n){
if(adj[v].find(a[last])==adj[v].end())return false;
dfs(a[last++],n);
}
return true;
}
int main() {
int n,m,x,y;
cin >> n >> m;
for(int i = 1;i<=n;i++){
cin >> a[i];
adj[i].insert(i);
}
for(int i=0;i<m;i++){
cin >> x >> y;
adj[x].insert(y);
adj[y].insert(x);
//adj[x][y] = adj[y][x] = 1;
}
if(dfs(1,n))cout << 1 << endl;
else cout << 0 << endl;
return 0;
}