# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
304576 | Akashi | Flood (IOI07_flood) | C++14 | 144 ms | 10596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int DIM = 1e5 + 5;
const int NWALL = 2e5 + 5;
///Nord, Vest, Sud, Est
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, w;
int x[DIM], y[DIM];
pair <int, int> wh[DIM][4];
int cnt[NWALL];
bool viz[NWALL];
struct elem {
int a, b, id;
bool operator < (const elem &aux) const{
if (x[a] != x[aux.a]) return x[a] < x[aux.a];
if (y[a] != y[aux.a]) return y[a] > y[aux.a];
if (x[b] != x[aux.b]) return x[b] < x[aux.b];
return y[b] > y[aux.b];
}
};
int opus(int dir) {
if (dir == 0 || dir == 2) dir = 2 - dir;
else dir = 4 - dir;
return dir;
}
void dfs(int nod, int dir, int root) {
if (dir == 4) dir = 0;
for (int d = dir + 1; d <= dir + 4 ; ++d) {
int real = d;
if (real >= 4) real -= 4;
if (wh[nod][real].first == 0 || viz[wh[nod][real].second]) continue ;
++cnt[wh[nod][real].second];
int aux = wh[nod][real].first;
wh[nod][real].first = 0;
if (aux != root)
dfs(aux, opus(real), root);
viz[wh[nod][real].second] = 1;
break ;
}
}
int main() {
#ifdef HOME
freopen("flood.in", "r", stdin);
freopen("flood.out", "w", stdout);
#endif // HOME
scanf("%d", &n);
for (int i = 1; i <= n ; ++i)
scanf("%d%d", &x[i], &y[i]);
scanf("%d", &w);
int a, b;
vector <elem> wall;
for (int i = 1; i <= w ; ++i) {
scanf("%d%d", &a, &b);
if (x[a] == x[b]) {
if (y[a] > y[b]) swap(a, b);
wh[a][0] = {b, i};
wh[b][2] = {a, i};
} else {
if (x[a] > x[b]) swap(a, b);
wh[a][3] = {b, i};
wh[b][1] = {a, i};
}
wall.push_back({b, a, i});
}
sort (wall.begin(), wall.end());
for (int i = 0; i < w ; ++i) {
if (cnt[wall[i].id]) continue ;
dfs(wall[i].a, 1, wall[i].a);
}
vector <int> sol;
for (int i = 1; i <= w ; ++i)
if (cnt[i] == 2) sol.push_back(i);
printf("%d\n", sol.size());
for (auto it : sol) printf("%d\n", it);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |