Submission #873462

# Submission time Handle Problem Language Result Execution time Memory
873462 2023-11-15T06:32:52 Z vjudge1 Colors (RMI18_colors) C++17
0 / 100
79 ms 12884 KB
#include<bits/stdc++.h>
using namespace std;
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#define f first 
#define s second
typedef long long ll;
ll d[200100],c[200100];
vector<ll> g[200100];
void solve(){    
    ll n,m,root=-1; cin>>n>>m;
    map<ll, bool> mp;
    for(ll i=1; i<=n; i++){
        cin>>d[i];
        mp[d[i]]=true;
    }
    for(ll i=1; i<=n; i++) cin>>c[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 u=1; u<=n; u++) if(g[u].size() > 1) root=u;
    vector<pair<ll, ll>> v;
    for(ll i=1; i<=n; i++){
        if(root == i) continue;
        v.push_back({c[i], d[i]});
    }
    sort(v.rbegin(), v.rend());
    for(auto to: v){
        if(to.f < to.s || !mp[to.s] || d[root] < to.s){
            cout<<"0";
            return;
        }
        d[root]=to.s;
    }
    if(d[root] < c[root] || !mp[c[root]]){
        cout<<"0";
        return;
    }
    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++){
        // cout<<"Case "<<i<<":\n";
        solve();
        cout<<'\n';
    }
}

# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 9808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 12616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 9624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 9624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 9808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 12884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 9308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 9808 KB Output isn't correct
2 Halted 0 ms 0 KB -