# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
873440 | 2023-11-15T05:43:57 Z | vjudge1 | Colors (RMI18_colors) | C++17 | 54 ms | 16736 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 14116 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 30 ms | 14912 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 28 ms | 13916 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 28 ms | 13916 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 14116 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 54 ms | 16736 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 11352 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 14116 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |