Submission #451362

#TimeUsernameProblemLanguageResultExecution timeMemory
451362prvocisloFlood (IOI07_flood)C++17
100 / 100
292 ms31152 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> typedef long long ll; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n; vector<int> x(n), y(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; cin >> m; vector<int> a(m), b(m); vector<vector<bool> > vis1(m, vector<bool>(2, false)); vector<bool> vis2(m, false); vector<vector<int> > g(n, vector<int>(4, -1)); set<pair<pair<int, int>, int>> pq; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--, b[i]--; if (x[b[i]] < x[a[i]] || y[b[i]] < y[a[i]]) swap(a[i], b[i]); if (y[a[i]] == y[b[i]]) { g[a[i]][0] = i; g[b[i]][2] = i; } if (x[a[i]] == x[b[i]]) { g[a[i]][3] = i; g[b[i]][1] = i; } pq.insert({ {-x[b[i]], y[b[i]]}, i }); } while (!pq.empty()) { int i = pq.begin()->second; pq.erase(pq.begin()); if (vis2[i]) continue; //cout << "\n"; int u = a[i], d = find(g[b[i]].begin(), g[b[i]].end(), i) - g[b[i]].begin(); vector<int> nw; while (true) { int e = -1, d2 = -1; for (int i = 3; i < 7; i++) { e = g[u][(d + i) % 4]; if (e != -1 && !vis2[e]) { d2 = (d + i) % 4; break; } } bool flag = a[e] == u; if (vis1[e][flag]) break; vis1[e][flag] = true; nw.push_back(e); u = u ^ a[e] ^ b[e], d = d2; //cout << e << "\n"; } for (int e : nw) vis2[e] = true; } vector<int> ans; for (int i = 0; i < m; i++) if (vis1[i][0] && vis1[i][1]) ans.push_back(i); cout << ans.size() << "\n"; for (int i : ans) cout << i + 1 << "\n"; return 0; }
#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...