# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
65959 |
2018-08-09T07:41:29 Z |
aome |
Flood (IOI07_flood) |
C++17 |
|
185 ms |
22212 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
int e[N][4];
int it[N << 2];
int T, st[N], ed[N];
int p[N], h[N], par[N];
int fr[N * 2], to[N * 2];
bool visit[N], del[N * 2];
pair<int, int> a[N];
vector<int> vec;
void add(int u, int v, int id) {
if (a[u].first == a[v].first) {
if (a[u].second < a[v].second) e[u][1] = id; else e[u][3] = id;
}
else {
if (a[u].first < a[v].first) e[u][2] = id; else e[u][0] = id;
}
}
void dfs(int u, int x) {
visit[u] = 1, x = (x + 3) % 4;
st[u] = ++T;
for (int i = 0; i < 4; ++i) {
int y = (x + i) % 4;
int id = e[u][y];
if (!id) continue;
int v = fr[id] ^ to[id] ^ u;
if (par[u] == id) continue;
if (visit[v]) {
if (h[u] > h[v]) vec.push_back(id);
continue;
}
par[v] = id, h[v] = h[u] + 1, dfs(v, y);
}
ed[u] = T;
}
void push(int i, int l, int r) {
if (l != r) {
it[i << 1] += it[i], it[i << 1 | 1] += it[i];
it[i] = 0;
}
}
void upd(int i, int l, int r, int L, int R) {
push(i, l, r);
if (l > R || L > r) return;
if (L <= l && r <= R) {
it[i]++, push(i, l, r); return;
}
int mid = (l + r) >> 1;
upd(i << 1, l, mid, L, R);
upd(i << 1 | 1, mid + 1, r, L, R);
}
int get(int i, int l, int r, int p) {
push(i, l, r);
if (l == r) return it[i];
int mid = (l + r) >> 1;
if (mid >= p) return get(i << 1, l, mid, p);
else return get(i << 1 | 1, mid + 1, r, p);
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) {
p[i] = i;
cin >> a[i].first >> a[i].second;
}
cin >> m;
for (int i = 1; i <= m; ++i) {
cin >> fr[i] >> to[i];
add(fr[i], to[i], i), add(to[i], fr[i], i);
}
sort(p + 1, p + 1 + n, [&] (int x, int y) {
return a[x] < a[y];
});
for (int i = 1; i <= n; ++i) {
if (visit[p[i]]) continue;
dfs(p[i], 2);
for (auto j : vec) {
int u = fr[j], v = to[j];
if (h[u] < h[v]) swap(u, v);
int fu = get(1, 1, n, st[u]);
int fv = get(1, 1, n, st[v]);
if (fu - fv) continue;
del[j] = 1;
while (u != v) {
int id = par[u];
upd(1, 1, n, st[u], ed[u]);
del[id] = 1, u = fr[id] ^ to[id] ^ u;
}
}
vec.clear();
}
int res = 0;
for (int i = 1; i <= m; ++i) if (!del[i]) ++res;
cout << res << '\n';
for (int i = 1; i <= m; ++i) if (!del[i]) cout << i << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
488 KB |
Output is correct |
2 |
Incorrect |
4 ms |
488 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
488 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
756 KB |
Output is correct |
2 |
Correct |
3 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
756 KB |
Output is correct |
2 |
Incorrect |
4 ms |
852 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
9924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
11588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
162 ms |
17036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
185 ms |
22212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |