Submission #873428

# Submission time Handle Problem Language Result Execution time Memory
873428 2023-11-15T05:17:12 Z vjudge1 Colors (RMI18_colors) C++17
0 / 100
308 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
ll a[200100],b[200100];
ll A[200100],B[200100];
bool used[200100];
vector<ll> g[200100];
vector<ll> c;
void dfs(ll v){
    c.push_back(v);
    used[v]=true;
    for(auto to: g[v]){
        if(used[to]) continue;
        dfs(v);
    }
}
void solve(){
    ll n,m; cin>>n>>m;
    for(ll i=1; i<=n; i++) cin>>A[i];
    for(ll i=1; i<=n; i++) cin>>B[i];
    for(ll i=1; i<=m; i++){
        ll u,v; cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(ll i=1; i<=n; i++){
        if(g[i].size() == 1){
            dfs(i);
            break;
        }
    }
    for(ll i=1; i<=c.size(); i++){
        a[i]=A[c[i-1]];
        b[i]=B[c[i-1]];
    }
    for(ll i=1; i<=n; i++){
        ll pos=-1;
        for(ll j=i+1; j<=n; j++){
            if(a[j] == b[i]){
                pos=j;
                break;
            }
        }
        if(pos == -1){
            cout<<"0";
            return;
        } else if(b[i] == a[i-1]){
            a[i]=b[i];
        } else{
            for(ll j=i; j<=pos; j++) a[j]=b[i];
        } 
    }
    cout<<"1";
}        
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);  
    int t=1;
    cin>>t;    
    for(int i=1; i<=t; i++){
        solve();
        cout<<'\n';
    }
}

Compilation message

colors.cpp: In function 'void solve()':
colors.cpp:34:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(ll i=1; i<=c.size(); i++){
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 308 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 14904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 245 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 245 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 308 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 255 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 11356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 308 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -