#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 = 5e5 + 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 = 0 ; i <= n; i++) g[i].clear() , used[i] = 0;
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() == m) rt = v ;
if(g[u].size() == m) rt = u ;
}
for(int i = 1 ; i <= n; i++){
if(a[rt] < b[i] && a[i] != b[i]){
cout << "0\n";
return ;
}
if(a[i] < b[i]){
cout << "0\n";
return ;
}
if(b[rt] > b[i] && b[i] != a[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: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[v].size() == m) rt = v ;
| ~~~~~~~~~~~~^~~~
colors.cpp:29:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
29 | if(g[u].size() == m) rt = u ;
| ~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
16984 KB |
Output is correct |
2 |
Correct |
12 ms |
17500 KB |
Output is correct |
3 |
Correct |
4 ms |
16988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
16988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
17240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
17240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
16984 KB |
Output is correct |
2 |
Correct |
12 ms |
17500 KB |
Output is correct |
3 |
Correct |
4 ms |
16988 KB |
Output is correct |
4 |
Incorrect |
28 ms |
17240 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
62 ms |
17112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
16984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
16984 KB |
Output is correct |
2 |
Correct |
12 ms |
17500 KB |
Output is correct |
3 |
Correct |
4 ms |
16988 KB |
Output is correct |
4 |
Incorrect |
30 ms |
16988 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |