Submission #643571

# Submission time Handle Problem Language Result Execution time Memory
643571 2022-09-22T13:34:37 Z DobromirAngelov Colors (RMI18_colors) C++14
47 / 100
3000 ms 5776 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

const int MAXN=150005;

int n,m;
int a[MAXN], b[MAXN];
vector<int> adj[MAXN];
bool used[MAXN];
stack<int> st;

bool bfs(int s)
{
    while(!st.empty())
    {
        used[st.top()]=0;
        st.pop();
    }
    int cur=s;
    stack<int> q;
    q.push(cur);
    used[cur]=1;
    st.push(cur);
    while(!q.empty())
    {
        cur=q.top();
        q.pop();
        for(int i=0;i<adj[cur].size();i++)
        {
            int next=adj[cur][i];
            if(!used[next] && (a[next]>=b[s] && b[s]>=b[next]))
            {
                if(a[next]==b[s]) return 1;
                used[next]=1;
                st.push(next);
                q.push(next);
            }
        }
    }
    return 0;
}

void init(int n)
{
    for(int i=1;i<=n;i++) adj[i].clear();
}

int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

int t;
cin>>t;
while(t--)
{
    cin>>n>>m;
    init(n);
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    bool fl=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<b[i])
        {
            cout<<0<<endl;
            fl=1;
            break;
        }
    }
    if(fl) continue;

    for(int i=1;i<=n;i++)
    {
        if(a[i]==b[i]) continue;
        if(!bfs(i))
        {
            cout<<0<<endl;
            fl=1;
            break;
        }
    }
    if(!fl) cout<<1<<endl;
}

return 0;
}

Compilation message

colors.cpp: In function 'bool bfs(int)':
colors.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i=0;i<adj[cur].size();i++)
      |                     ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 59 ms 3872 KB Output is correct
2 Correct 37 ms 3900 KB Output is correct
3 Correct 7 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3796 KB Output is correct
2 Correct 19 ms 3868 KB Output is correct
3 Correct 4 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3796 KB Output is correct
2 Correct 19 ms 3868 KB Output is correct
3 Correct 4 ms 3796 KB Output is correct
4 Correct 102 ms 3864 KB Output is correct
5 Execution timed out 3049 ms 5776 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 3872 KB Output is correct
2 Correct 37 ms 3900 KB Output is correct
3 Correct 7 ms 3924 KB Output is correct
4 Correct 48 ms 3796 KB Output is correct
5 Correct 19 ms 3868 KB Output is correct
6 Correct 4 ms 3796 KB Output is correct
7 Correct 69 ms 3872 KB Output is correct
8 Correct 37 ms 3900 KB Output is correct
9 Correct 33 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 3904 KB Output is correct
2 Execution timed out 3072 ms 5120 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3884 KB Output is correct
2 Correct 10 ms 3856 KB Output is correct
3 Correct 23 ms 3920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 3872 KB Output is correct
2 Correct 37 ms 3900 KB Output is correct
3 Correct 7 ms 3924 KB Output is correct
4 Correct 49 ms 3796 KB Output is correct
5 Correct 48 ms 3796 KB Output is correct
6 Correct 19 ms 3868 KB Output is correct
7 Correct 4 ms 3796 KB Output is correct
8 Correct 102 ms 3864 KB Output is correct
9 Execution timed out 3049 ms 5776 KB Time limit exceeded
10 Halted 0 ms 0 KB -