답안 #643570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643570 2022-09-22T13:31:42 Z DobromirAngelov Colors (RMI18_colors) C++14
47 / 100
3000 ms 8156 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;
    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[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++)
      |                     ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 3876 KB Output is correct
2 Correct 37 ms 4408 KB Output is correct
3 Correct 7 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 3864 KB Output is correct
2 Correct 20 ms 4308 KB Output is correct
3 Correct 4 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 3864 KB Output is correct
2 Correct 20 ms 4308 KB Output is correct
3 Correct 4 ms 3924 KB Output is correct
4 Correct 104 ms 6108 KB Output is correct
5 Execution timed out 3064 ms 8156 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 3876 KB Output is correct
2 Correct 37 ms 4408 KB Output is correct
3 Correct 7 ms 3924 KB Output is correct
4 Correct 56 ms 3864 KB Output is correct
5 Correct 20 ms 4308 KB Output is correct
6 Correct 4 ms 3924 KB Output is correct
7 Correct 75 ms 5244 KB Output is correct
8 Correct 38 ms 4372 KB Output is correct
9 Correct 39 ms 3972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 3896 KB Output is correct
2 Execution timed out 3082 ms 5824 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3772 KB Output is correct
2 Correct 11 ms 4200 KB Output is correct
3 Correct 20 ms 4000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 3876 KB Output is correct
2 Correct 37 ms 4408 KB Output is correct
3 Correct 7 ms 3924 KB Output is correct
4 Correct 48 ms 3796 KB Output is correct
5 Correct 56 ms 3864 KB Output is correct
6 Correct 20 ms 4308 KB Output is correct
7 Correct 4 ms 3924 KB Output is correct
8 Correct 104 ms 6108 KB Output is correct
9 Execution timed out 3064 ms 8156 KB Time limit exceeded
10 Halted 0 ms 0 KB -