#include <bits/stdc++.h>
using namespace std;
constexpr int nmax=5005;
vector<int> G[nmax];
bool sel[nmax][nmax];
int a[nmax],b[nmax];
void dfs(int nod, int culoare)
{
sel[nod][culoare]=true;
for(auto it: G[nod])
{
if(sel[it][culoare]==false && a[it]>=culoare && culoare>=b[it])dfs(it,culoare);
}
}
int main()
{
//freopen("colors.in","r",stdin);
//freopen("colors.out","w",stdout);
cin.sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
int n,m;
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)
{
for(int j=1; j<=n; ++j)
sel[j][i]=false;
for(int j=1; j<=n; ++j)
{
if(a[j]==i && sel[j][i]==false)dfs(j,i);
}
}
int rez=1;
for(int i=1; i<=n; ++i)
{
if(sel[i][b[i]]==false)
{
rez=0;
break;
}
}
cout<<rez<<'\n';
for(int i=1; i<=n; ++i)
{
G[i].clear();
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
1432 KB |
Output is correct |
2 |
Correct |
33 ms |
1528 KB |
Output is correct |
3 |
Correct |
21 ms |
5844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
1412 KB |
Output is correct |
2 |
Correct |
22 ms |
1448 KB |
Output is correct |
3 |
Correct |
17 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
1412 KB |
Output is correct |
2 |
Correct |
22 ms |
1448 KB |
Output is correct |
3 |
Correct |
17 ms |
5460 KB |
Output is correct |
4 |
Correct |
111 ms |
3828 KB |
Output is correct |
5 |
Runtime error |
7 ms |
1492 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
1432 KB |
Output is correct |
2 |
Correct |
33 ms |
1528 KB |
Output is correct |
3 |
Correct |
21 ms |
5844 KB |
Output is correct |
4 |
Correct |
57 ms |
1412 KB |
Output is correct |
5 |
Correct |
22 ms |
1448 KB |
Output is correct |
6 |
Correct |
17 ms |
5460 KB |
Output is correct |
7 |
Correct |
57 ms |
2052 KB |
Output is correct |
8 |
Correct |
28 ms |
1452 KB |
Output is correct |
9 |
Correct |
31 ms |
5940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
3124 KB |
Output is correct |
2 |
Runtime error |
6 ms |
1364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
596 KB |
Output is correct |
2 |
Correct |
21 ms |
1228 KB |
Output is correct |
3 |
Correct |
38 ms |
2868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
1432 KB |
Output is correct |
2 |
Correct |
33 ms |
1528 KB |
Output is correct |
3 |
Correct |
21 ms |
5844 KB |
Output is correct |
4 |
Correct |
78 ms |
912 KB |
Output is correct |
5 |
Correct |
57 ms |
1412 KB |
Output is correct |
6 |
Correct |
22 ms |
1448 KB |
Output is correct |
7 |
Correct |
17 ms |
5460 KB |
Output is correct |
8 |
Correct |
111 ms |
3828 KB |
Output is correct |
9 |
Runtime error |
7 ms |
1492 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |