Submission #873441

# Submission time Handle Problem Language Result Execution time Memory
873441 2023-11-15T05:49:14 Z vjudge1 Colors (RMI18_colors) C++17
0 / 100
62 ms 16796 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(to);
    }
}
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++){
        if(a[i] < b[i]){
            cout<<"0";
            return;
        }
        ll pos=-1;
        for(ll j=i; j<=n; j++){
            if(a[j] == b[i]){
                pos=j;
                break;
            }
        }
        // cout<<i<<" "<<pos<<"\n";
        if(b[i] == a[i-1]){
            a[i]=b[i];
        } else if(pos == -1){
            cout<<"0";
            return;
        } 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 Incorrect 30 ms 13920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 13908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 13908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 13920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 16796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 11352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 13920 KB Output isn't correct
2 Halted 0 ms 0 KB -