#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> x(n);
vector<int> y(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
x[i] *= 2;
y[i] *= 2;
}
int m;
cin >> m;
vector<int> a(m);
vector<int> b(m);
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i];
--a[i]; --b[i];
}
vector<pair<int, int>> pts;
for (int i = 0; i < n; i++) {
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
if (abs(dx) + abs(dy) == 2) {
pts.emplace_back(x[i] + dx, y[i] + dy);
}
}
}
}
sort(pts.begin(), pts.end());
pts.erase(unique(pts.begin(), pts.end()), pts.end());
int k = (int) pts.size();
map<int, vector<int>> xs;
map<int, vector<int>> ys;
for (int i = 0; i < k; i++) {
xs[pts[i].first].push_back(i);
ys[pts[i].second].push_back(i);
}
vector<vector<pair<int, int>>> g(k);
for (auto& p : xs) {
vector<int> id = p.second;
for (int i = 0; i + 1 < (int) id.size(); i++) {
g[id[i]].emplace_back(id[i + 1], 0);
g[id[i + 1]].emplace_back(id[i], 0);
}
}
for (auto& p : ys) {
vector<int> id = p.second;
for (int i = 0; i + 1 < (int) id.size(); i++) {
g[id[i]].emplace_back(id[i + 1], 0);
g[id[i + 1]].emplace_back(id[i], 0);
}
}
for (int i = 0; i < k; i++) {
sort(g[i].begin(), g[i].end());
g[i].erase(unique(g[i].begin(), g[i].end()), g[i].end());
}
auto Index = [&](int x, int y) {
pair<int, int> p = {x, y};
return (int) (lower_bound(pts.begin(), pts.end(), p) - pts.begin());
};
auto Update = [&](int i, int j) {
{
int idx = (int) (lower_bound(g[i].begin(), g[i].end(), make_pair(j, -1)) - g[i].begin());
g[i][idx].second = 1;
}
{
int idx = (int) (lower_bound(g[j].begin(), g[j].end(), make_pair(i, -1)) - g[j].begin());
g[j][idx].second = 1;
}
};
for (int i = 0; i < m; i++) {
if (x[a[i]] > x[b[i]] || y[a[i]] > y[b[i]]) {
swap(a[i], b[i]);
}
if (x[a[i]] == x[b[i]]) {
Update(Index(x[a[i]] - 1, y[a[i]] + 1), Index(x[a[i]] + 1, y[a[i]] + 1));
Update(Index(x[b[i]] - 1, y[b[i]] - 1), Index(x[b[i]] + 1, y[b[i]] - 1));
} else {
Update(Index(x[a[i]] + 1, y[a[i]] + 1), Index(x[a[i]] + 1, y[a[i]] - 1));
Update(Index(x[b[i]] - 1, y[b[i]] + 1), Index(x[b[i]] - 1, y[b[i]] - 1));
}
}
const int inf = (int) 1e9;
vector<int> dist(k, inf);
vector<int> order(k);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
return pts[i] < pts[j];
});
for (int v : order) {
if (dist[v] != inf) {
continue;
}
dist[v] = 0;
deque<int> dq;
dq.push_back(v);
while (!dq.empty()) {
int i = dq.front();
dq.pop_front();
for (auto& e : g[i]) {
int j = e.first;
int w = e.second;
if (dist[j] > dist[i] + w) {
dist[j] = dist[i] + w;
if (w == 0) {
dq.push_front(j);
} else {
dq.push_back(j);
}
}
}
}
}
vector<int> res;
for (int i = 0; i < m; i++) {
if (x[a[i]] == x[b[i]]) {
if (dist[Index(x[a[i]] - 1, y[a[i]] + 1)] == dist[Index(x[a[i]] + 1, y[a[i]] + 1)]) {
res.push_back(i);
}
} else {
if (dist[Index(x[a[i]] + 1, y[a[i]] - 1)] == dist[Index(x[a[i]] + 1, y[a[i]] + 1)]) {
res.push_back(i);
}
}
}
cout << (int) res.size() << '\n';
for (int i = 0; i < (int) res.size(); i++) {
cout << res[i] + 1 << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
13256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
207 ms |
35892 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
226 ms |
55652 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
363 ms |
48312 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
332 ms |
48836 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |