#include <bits/stdc++.h>
using namespace std ;
const int MAX = 2e5 + 10 ;
int a[MAX] , b[MAX] ;
int n , m ;
vector< vector<int> >adj(MAX) ;
vector<int>v[MAX] ;
set<int>s[MAX] ;
int par[MAX] ;
void init()
{
for(int i = 1 ; i <= n ; ++i)
par[i] = i , s[i].clear() , s[i].insert(a[i]) ;
}
int root(int node)
{
if(par[node] == node)
return node ;
return (par[node] = root(par[node])) ;
}
void Union(int x , int y)
{
int a = root(x) ;
int b = root(y) ;
if(a == b)
return ;
if(s[a].size() < s[b].size())
swap(a , b) ;
while(s[b].size())
s[a].insert(*s[b].begin()) , s[b].erase(s[b].begin()) ;
par[b] = a ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
int t ;
cin>>t ;
while(t--)
{
cin>>n>>m ;
for(int i = 1 ; i <= n ; ++i)
adj[i].clear() , v[i].clear() ;
for(int i = 1 ; i <= n ; ++i)
cin>>a[i] ;
for(int i = 1 ; i <= n ; ++i)
cin>>b[i] ;
for(int i = 0 ; i < m ; ++i)
{
int x , y ;
cin>>x>>y ;
adj[x].push_back(y) ;
adj[y].push_back(x) ;
}
init() ;
for(int i = 1 ; i <= n ; ++i)
v[b[i]].push_back(i) ;
bool flag = true ;
for(int i = 1 ; i <= n ; ++i)
{
for(auto &node : v[i])
{
for(auto &child : adj[node])
{
if(a[child] <= a[node])
Union(node , child) ;
}
}
for(auto &node : v[i])
{
int a = root(node) ;
if(s[a].find(i) == s[a].end())
flag = false ;
}
}
cout<<flag<<"\n" ;
}
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
81 ms |
20716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
20844 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
95 ms |
20716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
95 ms |
20716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
81 ms |
20716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
176 ms |
22320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
20036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
81 ms |
20716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |