Submission #908776

# Submission time Handle Problem Language Result Execution time Memory
908776 2024-01-16T20:16:27 Z Andreibatman Colors (RMI18_colors) C++14
47 / 100
3000 ms 8556 KB
#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;
        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;
                }
            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
1 Correct 58 ms 5980 KB Output is correct
2 Correct 37 ms 6188 KB Output is correct
3 Correct 21 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 6152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 5976 KB Output is correct
2 Correct 27 ms 5976 KB Output is correct
3 Correct 14 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 5976 KB Output is correct
2 Correct 27 ms 5976 KB Output is correct
3 Correct 14 ms 5976 KB Output is correct
4 Correct 116 ms 5980 KB Output is correct
5 Execution timed out 3038 ms 8556 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 5980 KB Output is correct
2 Correct 37 ms 6188 KB Output is correct
3 Correct 21 ms 5976 KB Output is correct
4 Correct 53 ms 5976 KB Output is correct
5 Correct 27 ms 5976 KB Output is correct
6 Correct 14 ms 5976 KB Output is correct
7 Correct 58 ms 5980 KB Output is correct
8 Correct 34 ms 6168 KB Output is correct
9 Correct 24 ms 6192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 5976 KB Output is correct
2 Execution timed out 3062 ms 7004 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 6232 KB Output is correct
2 Correct 19 ms 6228 KB Output is correct
3 Correct 34 ms 6236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 5980 KB Output is correct
2 Correct 37 ms 6188 KB Output is correct
3 Correct 21 ms 5976 KB Output is correct
4 Correct 61 ms 6152 KB Output is correct
5 Correct 53 ms 5976 KB Output is correct
6 Correct 27 ms 5976 KB Output is correct
7 Correct 14 ms 5976 KB Output is correct
8 Correct 116 ms 5980 KB Output is correct
9 Execution timed out 3038 ms 8556 KB Time limit exceeded
10 Halted 0 ms 0 KB -