# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
873470 | 2023-11-15T06:48:07 Z | vjudge1 | Colors (RMI18_colors) | C++17 | 56 ms | 10980 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(){ c.clear(); ll n,m; cin>>n>>m; for(ll i=1; i<=n; i++){ g[i].clear(); used[i]=false; a[i]=0; b[i]=0; 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 30 ms | 10840 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 28 ms | 10844 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 10844 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 10844 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 30 ms | 10840 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 56 ms | 10980 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 10844 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 30 ms | 10840 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |