Submission #643569

# Submission time Handle Problem Language Result Execution time Memory
643569 2022-09-22T13:29:14 Z DobromirAngelov Colors (RMI18_colors) C++14
0 / 100
164 ms 6956 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 cur)
{
    while(!st.empty())
    {
        used[st.top()]=0;
        st.pop();
    }
    queue<int> q;
    q.push(cur);
    used[cur]=1;
    st.push(cur);
    while(!q.empty())
    {
        cur=q.front();
        q.pop();
        for(int i=0;i<adj[cur].size();i++)
        {
            int next=adj[cur][i];
            if(!used[next] && (a[next]>=b[cur] && b[cur]>=b[next]))
            {
                if(a[next]==b[cur]) 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:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int i=0;i<adj[cur].size();i++)
      |                     ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 5264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 5528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 5244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 5244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 5264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 6956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 4624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 5264 KB Output isn't correct
2 Halted 0 ms 0 KB -