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 <iostream>
#include <algorithm>
#include <vector>
const int MAXN = 1e5;
int x[MAXN], y[MAXN];
int order[MAXN];
int graph[MAXN][4];
int id[MAXN][4];
int degree[MAXN];
std::vector<int> standing;
void brk(int node, int dir, int start)
{
for (int iDir = 5; iDir > 1; iDir--)
{
int nxt = graph[node][(dir + iDir) % 4];
if (nxt != -1)
{
if (nxt != start)
brk(nxt, (dir + iDir) % 4, start);
if (graph[node][(dir + iDir) % 4] == -1)
standing.emplace_back(id[node][(dir + iDir) % 4]);
else
{
degree[node]--;
degree[nxt]--;
graph[node][(dir + iDir) % 4] = -1;
graph[nxt][(dir + iDir + 2) % 4] = -1;
}
return;
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
int points; std::cin >> points;
for (int iPoint = 0; iPoint < points; iPoint++)
{
std::cin >> x[iPoint] >> y[iPoint];
order[iPoint] = iPoint;
for (int iDir = 0; iDir < 4; iDir++)
graph[iPoint][iDir] = -1;
}
int walls; std::cin >> walls;
for (int iWall = 0; iWall < walls; iWall++)
{
int u, v;
std::cin >> u >> v;
u--; v--;
if (x[u] == x[v])
{
int dir = 0;
if (y[u] > y[v])
dir += 2;
graph[u][dir] = v;
graph[v][2 - dir] = u;
id[u][dir] = iWall;
id[v][2 - dir] = iWall;
}
else
{
int dir = 1;
if (x[u] < x[v])
dir += 2;
graph[u][dir] = v;
graph[v][4 - dir] = u;
id[u][dir] = iWall;
id[v][4 - dir] = iWall;
}
degree[u]++;
degree[v]++;
}
std::sort(order, order + points, [](int a, int b) { return (x[a] < x[b]); });
for (int iNode = 0; iNode < points; iNode++)
while (degree[order[iNode]] != 0)
brk(order[iNode], 0, order[iNode]);
std::cout << standing.size() << '\n';
for (int wall : standing)
std::cout << wall + 1 << '\n';
return 0;
}
# | 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... |