#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <string>
#include <numeric>
#include <cmath>
#include <cassert>
#include <array>
#include <numeric>
using namespace std;
struct Point
{
array<int, 4> dir{-1, -1, -1, -1};
int x, y;
};
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<Point> points(n);
for (Point &i : points) cin >> i.x >> i.y;
int w;
cin >> w;
vector<int> adj(2 * w);
vector<tuple<int, int, int>> segms(w);
for (int i = 0; i < w; ++i)
{
int a, b;
cin >> a >> b;
--a;
--b;
segms[i] = {a, b, 0};
if (points[a].x == points[b].x)
{
if (points[a].y > points[b].y) swap(a, b);
get<2>(segms[i]) = 3;
points[a].dir[1] = 2 * i;
points[b].dir[3] = 2 * i + 1;
}
else
{
if (points[a].x > points[b].x) swap(a, b);
get<2>(segms[i]) = 0;
points[a].dir[2] = 2 * i;
points[b].dir[0] = 2 * i + 1;
}
get<0>(segms[i]) = a;
get<1>(segms[i]) = b;
}
int cnt = 0;
for (auto [a, b, c] : segms)
{
for (int i = (c + 1) % 4; ; i = (i + 1) % 4)
{
if (points[b].dir[i] != -1)
{
adj[2 * cnt] = points[b].dir[i];
break;
}
}
for (int i = (c + 3) % 4; ; i = (i + 1) % 4)
{
if (points[a].dir[i] != -1)
{
adj[2 * cnt + 1] = points[a].dir[i];
break;
}
}
++cnt;
}
vector<int> used(2 * w, -1);
auto dfs = [&adj, &used](auto self, int v, int face) -> void
{
used[v] = face;
if (used[adj[v]] == -1) self(self, adj[v], face);
};
int counter = 0;
for (int i = 0; i < 2 * w; ++i)
{
if (used[i] == -1)
{
dfs(dfs, i, counter);
++counter;
}
}
vector<vector<pair<int, int>>> faces(counter);
for (int i = 0; i < w; ++i)
{
faces[used[2 * i]].emplace_back(i, used[2 * i + 1]);
faces[used[2 * i + 1]].emplace_back(i, used[2 * i]);
}
int start;
set<pair<int, int>> hor, vert;
{
int left = -1, up = -1, i = 0;
for (auto [a, b, c] : segms)
{
if (points[a].x == points[b].x) vert.insert({points[a].x, i});
else hor.insert({points[a].y, i});
++i;
}
if (left != -1) start = used[2 * left];
else start = used[2 * up];
}
vector<int> saved = used;
used = vector<int>(counter);
vector<bool> isDel(w);
while (!hor.empty() || !vert.empty())
{
int start;
{
if (!vert.empty()) start = saved[2 * (vert.begin()->second)];
else start = saved[2 * (hor.begin()->second)];
}
vector<int> next{start};
used[start] = 1;
while (!next.empty())
{
set<int> nnext;
for (int f : next)
{
for (auto [v, f2] : faces[f])
{
if (!used[f2])
{
nnext.insert(f2);
isDel[v] = true;
}
auto [a, b, c] = segms[v];
if (points[a].x == points[b].x) vert.erase({points[a].x, v});
else hor.erase({points[a].y, v});
}
}
next.clear();
for (int i : nnext)
{
next.push_back(i);
used[i] = true;
}
}
}
vector<int> res;
for (int i = 0; i < w; ++i) if (!isDel[i]) res.push_back(i + 1);
cout << res.size() << '\n';
for (int i : res) cout << i << '\n';
return 0;
}
Compilation message
flood.cpp: In function 'int main()':
flood.cpp:98:9: warning: variable 'start' set but not used [-Wunused-but-set-variable]
98 | int start;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
10864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
13156 KB |
Output is correct |
2 |
Correct |
272 ms |
19708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
260 ms |
16556 KB |
Output is correct |
2 |
Correct |
231 ms |
20428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
333 ms |
19452 KB |
Output is correct |
2 |
Correct |
80 ms |
12456 KB |
Output is correct |