이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
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... |