Submission #129843

#TimeUsernameProblemLanguageResultExecution timeMemory
129843khulegubFlood (IOI07_flood)C++14
100 / 100
113 ms13040 KiB
#include <bits/stdc++.h> #define xx first #define yy second #define mp make_pair #define pb push_back using namespace std; typedef pair<int, int> pii; typedef long long i64; int xac = 0; int n; int w; // bool dbg = 0; pii to[100010][4]; bool path[100010]; int arr[4][4]; vector<int> uld; vector<pair<pair<int, int> , int> > p; int dfs(int u, int dir){ if (path[u]) return u; path[u] = 1; for (int i = 0; i < 4; i++){ int v = to[u][arr[dir][i]].xx; if (v != 0){ to[u][arr[dir][i]].xx = 0; to[v][ (arr[dir][i] + 2) % 4 ].xx = 0; int tmp = dfs(v, arr[dir][i]); if (tmp != -1){ if (tmp != u){ path[u] = 0; return tmp; } } else{ uld.pb(to[u][arr[dir][i]].yy); } } } path[u] = 0; return -1; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // freopen("in.txt", "r", stdin); cin >> n; for (int i = 0; i < 4; i++){ arr[i][0] = (i + 1) % 4; arr[i][1] = i; arr[i][2] = (i + 3) % 4; arr[i][3] = (i + 2) % 4; } p.resize(n + 1); p[0] = mp(mp(-1,-1),-1); for (int i = 1, tx, ty; i <= n; i++){ cin >> tx >> ty; p[i] = mp(mp(tx,ty), i); } cin >> w; for (int i = 1, a, b; i <= w; i++){ cin >> a >> b; int dir, dx, dy; dx = p[b].xx.xx - p[a].xx.xx; dy = p[b].xx.yy - p[a].xx.yy; if (dx != 0){ if (dx > 0) dir = 1; else dir = 3; } else{ if (dy > 0) dir = 0; else dir = 2; } to[a][dir] = mp(b, i); to[b][(dir + 2) % 4] = mp(a, i); } sort(p.begin(), p.end()); for (int i = 1; i <= n; i++){ dfs(p[i].yy, 0); } cout << uld.size() << '\n'; for (int a : uld){ cout << a << '\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...