#include <bits/stdc++.h>
using namespace std;
int n,m;
int a[100005],b[100005];
bool sel[100005];
bool ok[100005];
vector<int> G[100005];
void dfs(int nod, int cul)
{
sel[nod] = true;
if(b[nod]>cul || a[nod]<cul)
{
return;
}
if(b[nod]==cul)
{
ok[nod] = true;
}
for(auto it : G[nod])
{
if(sel[it])
{
continue;
}
dfs(it,cul);
}
}
void solve_test()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
cin>>b[i];
}
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
for(int i=1;i<=n;i++)
{
dfs(i,a[i]);
for(int j=1;j<=n;j++)
{
sel[j] = false;
}
}
bool rez = true;
for(int i=1;i<=n;i++)
{
if(!ok[i])
{
rez = false;
}
G[i].clear();
ok[i] = false;
}
cout<<rez<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
for(int test=1; test<=t; test++)
{
solve_test();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
4096 KB |
Output is correct |
2 |
Correct |
32 ms |
3192 KB |
Output is correct |
3 |
Correct |
19 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
4340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
4172 KB |
Output is correct |
2 |
Correct |
15 ms |
3156 KB |
Output is correct |
3 |
Correct |
4 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
4172 KB |
Output is correct |
2 |
Correct |
15 ms |
3156 KB |
Output is correct |
3 |
Correct |
4 ms |
2772 KB |
Output is correct |
4 |
Correct |
87 ms |
5736 KB |
Output is correct |
5 |
Execution timed out |
3051 ms |
8696 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
4096 KB |
Output is correct |
2 |
Correct |
32 ms |
3192 KB |
Output is correct |
3 |
Correct |
19 ms |
2812 KB |
Output is correct |
4 |
Correct |
44 ms |
4172 KB |
Output is correct |
5 |
Correct |
15 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
2772 KB |
Output is correct |
7 |
Correct |
53 ms |
4084 KB |
Output is correct |
8 |
Correct |
27 ms |
3200 KB |
Output is correct |
9 |
Correct |
13 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
5836 KB |
Output is correct |
2 |
Execution timed out |
3041 ms |
4908 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
3456 KB |
Output is correct |
2 |
Correct |
16 ms |
2936 KB |
Output is correct |
3 |
Correct |
31 ms |
2864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
4096 KB |
Output is correct |
2 |
Correct |
32 ms |
3192 KB |
Output is correct |
3 |
Correct |
19 ms |
2812 KB |
Output is correct |
4 |
Correct |
55 ms |
4340 KB |
Output is correct |
5 |
Correct |
44 ms |
4172 KB |
Output is correct |
6 |
Correct |
15 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
2772 KB |
Output is correct |
8 |
Correct |
87 ms |
5736 KB |
Output is correct |
9 |
Execution timed out |
3051 ms |
8696 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |