Submission #456356

#TimeUsernameProblemLanguageResultExecution timeMemory
456356dutchFlood (IOI07_flood)C++17
100 / 100
241 ms26052 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+1, M = N+N, INF = 1e9; int n, m, c[2][N], e[2][M], d[M*2], h[4][N], p; bool vert[M], vis[M*2]; vector<int> g[M*2]; signed main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; for(int i=1; i<=n; ++i) cin >> c[0][i] >> c[1][i]; cin >> m; for(int i=1; i<=m; ++i){ int &u = e[0][i], &v = e[1][i]; cin >> u >> v; vert[i] = (c[0][u] == c[0][v]); if(c[vert[i]][u] > c[vert[i]][v]) swap(u, v); h[2+!vert[i]][u] = h[!vert[i]][v] = i; } vis[0] = 1; for(int i=1; i<=m+m; ++i){ int u = i, v; while(!vis[u]){ vis[u] = !(v = 0); int w = u; u = u > m ? u - m : u; int s = e[vert[u] ^ (w > m)][u]; array<int, 4> add = {vert[u] == (w > m), w > m}; for(int j=0; j<4; ++j){ int k = (j + vert[u] + (w > m) * 2) % 4; if(h[k][s] && !v) v = h[k][s] + m * (add[j & 1] ^ (j > 1)); } if(v){ g[w].push_back(v); g[v].push_back(w); } u = v; } } deque<int> q; array<int, 2> todo[m]; for(int i=1; i<=m; ++i) todo[i-1] = {c[!vert[i]][e[0][i]], i}; sort(todo, todo+m); fill(d, d+m+m+1, INF); while(p < m){ q.push_back(todo[p][1]); d[todo[p][1]] = 0; while(!q.empty()){ int u = q.front(); q.pop_front(); for(int v : g[u]) if(d[v] > d[u]){ d[v] = d[u]; q.push_front(v); } int v = u > m ? u-m : u+m; if(d[v] > d[u] + 1){ d[v] = d[u] + 1; q.push_back(v); } if(d[u] == d[v]) vis[min(u, v)] = 0; } while(p < m && d[todo[p][1]] < INF) ++p; } cout << m-accumulate(vis+1, vis+1+m, 0) << '\n'; for(int i=1; i<=m; ++i) if(!vis[i]) cout << i << '\n'; }
#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...
#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...