This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
queue<int>q;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
cin>>n>>m;
for(i=1;i<=n;i++)
v[i].clear();
for(i=1;i<=n;i++)
cin>>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--)
{
while(!q.empty())
q.pop();
for(i=1;i<=n;i++)
if(a[i]==color)
{
q.push(i);
viz[i]=color;
}
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);
}
}
}
ok=1;
for(i=1;i<=n;i++)
if(a[i]!=b[i])
ok=0;
cout<<ok<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |