Submission #557862

#TimeUsernameProblemLanguageResultExecution timeMemory
557862FatihSolakColors (RMI18_colors)C++17
30 / 100
3065 ms524288 KiB
#include <bits/stdc++.h> #define N 200005 using namespace std; int a[N]; int b[N]; vector<int> adj[N]; set<int> s[N]; bool ok[N]; void dfs(int v,int par){ s[v] = {a[v]}; for(auto u:adj[v]){ if(u == par)continue; dfs(u,v); if(s[v].size() < s[u].size()) swap(s[v],s[u]); for(auto c:s[u]) s[v].insert(c); } while(*s[v].begin() < b[v]) s[v].erase(*s[v].begin()); while(*s[v].rbegin() > a[v]) s[v].erase(*s[v].rbegin()); if(s[v].count(b[v])) ok[v] = 1; } void solve(){ int n,m; cin >> n >> m; for(int i = 1;i<=n;i++){ cin >> a[i]; adj[i].clear(); ok[i] = 0; } for(int i = 1;i<=n;i++){ cin >> b[i]; } for(int i = 1;i<=m;i++){ int u,v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for(int i = 1;i<=n;i++){ if(a[i] < b[i]){ cout << 0 << endl; return; } } for(int i = 1;i<=n;i++){ dfs(i,0); } for(int i = 1;i<=n;i++){ if(!ok[i]){ cout << 0 << endl; return; } } cout << 1 << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; cin >> t; while(t--){ solve(); } #ifdef Local cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds."; #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...