Submission #121258

#TimeUsernameProblemLanguageResultExecution timeMemory
121258win11905Flood (IOI07_flood)C++11
10 / 100
1232 ms34672 KiB
#include <bits/stdc++.h> #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 1e5; int n, m; int x[N], y[N]; int s[N<<1], t[N<<1]; int za[N<<1], zb[N<<1]; bitset<4> state[N]; int idx; map<pii, int> Mp; vector<int> coor; int par[N<<2]; int lv[N>>1]; vector<int> g[N>>1]; int get(int x) { return lower_bound(coor.begin(), coor.end(), x) - coor.begin(); } int find(int u) { return par[u] = par[u] == u ? u : find(par[u]); } void merge(int a, int b, int c, int d) { int u = Mp[pii(a, b)], v = Mp[pii(c, d)]; par[find(u)] = find(v); } int main() { iota(par, par+(N<<1), 0); scanf("%d", &n); int mnx = 1e9, st; for(int i = 0; i < n; ++i) { scanf("%d %d", x+i, y+i); Mp[pii(x[i], y[i])] = ++idx; Mp[pii(x[i]+1, y[i])] = ++idx; Mp[pii(x[i], y[i]+1)] = ++idx; Mp[pii(x[i]+1, y[i]+1)] = ++idx; if(x[i] < mnx) mnx = x[i], st = i; } scanf("%d", &m); for(int i = 0; i < m; ++i) { scanf("%d %d", s+i, t+i), s[i]--, t[i]--; if(x[s[i]] != x[t[i]]) { if(x[s[i]] > x[t[i]]) swap(s[i], t[i]); state[s[i]][1] = state[t[i]][3] = true; merge(x[s[i]]+1, y[s[i]], x[t[i]], y[t[i]]); merge(x[s[i]]+1, y[s[i]]+1, x[t[i]], y[t[i]]+1); } else { if(y[s[i]] > y[t[i]]) swap(s[i], t[i]); state[s[i]][0] = state[t[i]][2] = true; merge(x[s[i]], y[s[i]]+1, x[t[i]], y[t[i]]); merge(x[s[i]]+1, y[s[i]]+1, x[t[i]]+1, y[t[i]]); } } for(int i = 0; i < n; ++i) { if(!state[i][0]) merge(x[i], y[i]+1, x[i]+1, y[i]+1); if(!state[i][1]) merge(x[i]+1, y[i], x[i]+1, y[i]+1); if(!state[i][2]) merge(x[i], y[i], x[i]+1, y[i]); if(!state[i][3]) merge(x[i], y[i], x[i], y[i]+1); } for(int i = 0; i < m; ++i) { int a, b; if(x[s[i]] != x[t[i]]) a = find(Mp[pii(x[s[i]]+1, y[s[i]])]), b = find(Mp[pii(x[s[i]]+1, y[s[i]]+1)]); else a = find(Mp[pii(x[s[i]], y[s[i]]+1)]), b = find(Mp[pii(x[s[i]]+1, y[s[i]]+1)]); za[i] = a, zb[i] = b; coor.emplace_back(a), coor.emplace_back(b); } int start = find(Mp[pii(x[st], y[st])]); lv[start] = 1; Mp.clear(); sort(coor.begin(), coor.end()); coor.resize(unique(coor.begin(), coor.end()) - coor.begin()); start = get(start); for(int i = 0; i < m; ++i) za[i] = get(za[i]), zb[i] = get(zb[i]), g[za[i]].emplace_back(i), g[zb[i]].emplace_back(i); queue<int> Q; Q.emplace(start); vector<int> ans; while(!Q.empty()) { int u = Q.front(); Q.pop(); for(int x : g[u]) { int v = za[x] ^ zb[x] ^ u; if(lv[v] == 0) lv[v] = lv[u] + 1, Q.emplace(v); if(lv[v] != lv[u] + 1 && lv[v] != lv[u] - 1) ans.emplace_back(x); } } sort(ans.begin(), ans.end()); int z = (int)ans.size() >> 1; printf("%d\n", z); for(int i = 0; i < z; ++i) printf("%d\n", ans[i<<1|1] + 1); }

Compilation message (stderr)

flood.cpp: In function 'int main()':
flood.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
flood.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", x+i, y+i);
         ~~~~~^~~~~~~~~~~~~~~~~~~
flood.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &m);
     ~~~~~^~~~~~~~~~
flood.cpp:46:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", s+i, t+i), s[i]--, t[i]--;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
#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...