#include<bits/stdc++.h>
using namespace std;
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#define f first
#define s second
typedef long long ll;
ll A[200100],B[200100];
vector<ll> g[200100];
void solve(){
ll n,m,root=-1; cin>>n>>m;
map<ll, bool> mp;
for(ll i=1; i<=n; i++) g[i].clear();
for(ll i=1; i<=n; i++){
cin>>A[i];
mp[A[i]]=true;
}
for(ll i=1; i<=n; i++) cin>>B[i];
for(ll i=1; i<=m; i++){
ll u,v; cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
for(ll u=1; u<=n; u++) if(g[u].size() > 1) root=u;
vector<pair<ll, ll>> v;
for(ll i=1; i<=n; i++){
if(root == i) continue;
v.push_back({B[i], A[i]});
}
sort(v.rbegin(), v.rend());
for(auto to: v){
if(to.s < to.f || !mp[to.f] || A[root] < to.f){
cout<<"0";
return;
}
A[root]=to.f;
}
mp.clear();
for(ll i=1; i<=n; i++){
if(i == root) mp[A[i]]=true;
else mp[B[i]]=true;
}
if(A[root] < B[root] || !mp[B[root]]){
cout<<"0";
return;
}
cout<<"1";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
for(int i = 1; i <= t; i++){
// cout<<"Case "<<i<<":\n";
solve();
cout<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
7168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
7036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
7036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
7168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
83 ms |
6852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
7168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |