#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); }
const int MOD = 1e9 + 7;
const int MX = 1e5 + 10;
const ll INF = 1e18;
int N, W; int X[MX], Y[MX], A[MX], B[MX]; vi P; pi adj[MX][4]; int deg[MX];
bool vis[MX][4]; set<int> allWalls; vi ans;
void DFS(int curPoint, int curDir) {
vis[curPoint][curDir] = true;
FOR(i, -1, 3) {
int nDir = (curDir + i + 4) % 4;
if (adj[curPoint][nDir].f != 0) {
int nPoint = adj[curPoint][nDir].f;
int curWall = adj[curPoint][nDir].s;
if (!vis[nPoint][nDir]) {
if (allWalls.count(curWall)) {
ans.pb(curWall);
}
else {
allWalls.insert(curWall);
}
DFS(nPoint, nDir);
}
break;
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N; FOR(i, 1, N + 1) cin >> X[i] >> Y[i];
P.rsz(N); iota(all(P), 1); sort(all(P), [&](int a, int b) { return X[a] == X[b] ? Y[a] < Y[b] : X[a] < X[b]; });
cin >> W; F0R(i, W) {
cin >> A[i] >> B[i];
if (X[A[i]] == X[B[i]]) {
if (Y[A[i]] > Y[B[i]]) swap(A[i], B[i]);
adj[A[i]][1] = {B[i], i};
adj[B[i]][3] = {A[i], i};
}
if (Y[A[i]] == Y[B[i]]) {
if (X[A[i]] > X[B[i]]) swap(A[i], B[i]);
adj[A[i]][0] = {B[i], i};
adj[B[i]][2] = {A[i], i};
}
deg[A[i]]++, deg[B[i]]++;
}
EACH(point, P) {
if (deg[point] == 0) continue;
int DIR = 0; F0R(dir, 4) if (!vis[point][dir]) { DIR = dir; break; }
DFS(point, DIR);
EACH(i, allWalls) {
if (X[A[i]] == X[B[i]]) {
adj[A[i]][1] = {0, 0};
adj[B[i]][3] = {0, 0};
}
if (Y[A[i]] == Y[B[i]]) {
adj[A[i]][0] = {0, 0};
adj[B[i]][2] = {0, 0};
}
deg[A[i]]--, deg[B[i]]--;
}
allWalls.clear();
}
cout << sz(ans) << "\n"; EACH(i, ans) cout << i + 1 << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
11712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
7888 KB |
Output is correct |
2 |
Incorrect |
117 ms |
9248 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
103 ms |
9156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
112 ms |
9284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |