#include <bits/stdc++.h>
#define NMAX 150010
using namespace std;
vector<int>v[NMAX];
int a[NMAX],b[NMAX],n,m,x,y,i,j,ok,t,color,viz[NMAX],p,culoare[NMAX];
queue<int>q;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
cin>>n>>m;
ok=1;
for(i=1;i<=n;i++)
v[i].clear();
for(i=1;i<=n;i++)
{
cin>>a[i];
culoare[a[i]]++;
}
for(i=1;i<=n;i++)
cin>>b[i];
for(i=1;i<=m;i++)
{
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
for(color=n;color>=1;color--)
{
if(culoare[color]==0)
continue;
while(!q.empty())
q.pop();
for(i=1;i<=n;i++)
if(a[i]==color)
{
q.push(i);
viz[i]=color;
}
else if(a[i]!=b[i] && color<b[i])
{
ok=0;
break;
}
if(ok==0)
break;
while(!q.empty())
{
p=q.front();
q.pop();
for(auto it:v[p])
if(viz[it]!=color && a[it]>color && a[it]>b[it])
{
a[it]=color;
viz[it]=color;
q.push(it);
}
}
}
for(i=1;i<=n;i++)
if(a[i]!=b[i])
ok=0;
cout<<ok<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
7004 KB |
Output is correct |
2 |
Correct |
34 ms |
6492 KB |
Output is correct |
3 |
Correct |
15 ms |
6236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
6996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
6992 KB |
Output is correct |
2 |
Correct |
26 ms |
6672 KB |
Output is correct |
3 |
Correct |
12 ms |
6236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
6992 KB |
Output is correct |
2 |
Correct |
26 ms |
6672 KB |
Output is correct |
3 |
Correct |
12 ms |
6236 KB |
Output is correct |
4 |
Correct |
116 ms |
7916 KB |
Output is correct |
5 |
Execution timed out |
3025 ms |
7936 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
7004 KB |
Output is correct |
2 |
Correct |
34 ms |
6492 KB |
Output is correct |
3 |
Correct |
15 ms |
6236 KB |
Output is correct |
4 |
Correct |
51 ms |
6992 KB |
Output is correct |
5 |
Correct |
26 ms |
6672 KB |
Output is correct |
6 |
Correct |
12 ms |
6236 KB |
Output is correct |
7 |
Correct |
65 ms |
6992 KB |
Output is correct |
8 |
Correct |
31 ms |
6488 KB |
Output is correct |
9 |
Correct |
17 ms |
6232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
8016 KB |
Output is correct |
2 |
Execution timed out |
3054 ms |
7516 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
6912 KB |
Output is correct |
2 |
Correct |
20 ms |
6488 KB |
Output is correct |
3 |
Correct |
22 ms |
6156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
7004 KB |
Output is correct |
2 |
Correct |
34 ms |
6492 KB |
Output is correct |
3 |
Correct |
15 ms |
6236 KB |
Output is correct |
4 |
Correct |
61 ms |
6996 KB |
Output is correct |
5 |
Correct |
51 ms |
6992 KB |
Output is correct |
6 |
Correct |
26 ms |
6672 KB |
Output is correct |
7 |
Correct |
12 ms |
6236 KB |
Output is correct |
8 |
Correct |
116 ms |
7916 KB |
Output is correct |
9 |
Execution timed out |
3025 ms |
7936 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |