#include <bits/stdc++.h>
#define f first
#define S second
#define pb push_back
#define msk(x , y) ((x >> y) & 1)
#define all(x) x.begin() , x.end()
using namespace std;
typedef long long int ll;
const int N = 2e5 + 7;
const ll mod = 1e18;
const int dx[] = {-1,-1,1,1,2,-2,2,-2};
const int dy[] = {-2,2,2,-2,1,1,-1,-1};
int n , m , a[N] , b[N] , used[N];
vector <int > g[N];
void solve(){
cin >> n >> m ;
for(int i = 1 ; i <= n; i++)cin >> a[i];
for(int i = 1 ; i <= n; i++)cin >> b[i];
int rt = 0 ;
for(int i = 1 ; i <= m; i++){
int u , v;
cin >> u >> v ;
g[u].pb(v);
g[v].pb(u);
if(g[v].size() == n - 1) rt = v ;
if(g[u].size() == n - 1) rt = u ;
}
for(int i = 1 ; i <= n; i++){
if(a[rt] < b[i]){
cout << "0\n";
return ;
}
if(a[i] < b[i]){
cout << "0\n";
return ;
}
used[a[i]] = 1;
}
for(int i = 1 ; i <= n; i++){
if(used[b[i]]) continue ;
cout << "0\n";
return ;
}
cout << "1\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test=1;
cin >> test ;
for(int i=1;i<=test;i++){
// cout << "Case " << i << ": ";
solve();
}
}
Compilation message
colors.cpp: In function 'void solve()':
colors.cpp:27:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
27 | if(g[v].size() == n - 1) rt = v ;
| ~~~~~~~~~~~~^~~~~~~~
colors.cpp:28:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
28 | if(g[u].size() == n - 1) rt = u ;
| ~~~~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
9812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
11612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
9816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
9816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
9812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
66 ms |
12880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
9812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |