#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[2 * MX], B[2 * MX]; vi P; pi adj[MX][4];
bool vis[MX][4]; unordered_set<int> allWalls, ans;
void DFS(int curPoint, int curDir) {
if (vis[curPoint][curDir]) return ;
vis[curPoint][curDir] = true;
int nPoint = adj[curPoint][curDir].f;
int curWall = adj[curPoint][curDir].s;
if (allWalls.count(curWall)) {
ans.insert(curWall);
}
else {
allWalls.insert(curWall);
}
FOR(i, -1, 3) {
int nDir = (curDir + i + 4) % 4;
if (adj[nPoint][nDir].f != -1) {
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]; });
FOR(i, 1, N + 1) F0R(j, 4) adj[i][j] = {-1, -1};
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};
}
}
EACH(point, P) {
int DIR = -1; F0R(dir, 4) if (!vis[point][dir] && adj[point][dir].f != -1) { DIR = dir; break; }
if (DIR == -1) continue;
allWalls.clear(); DFS(point, DIR);
EACH(i, allWalls) {
if (X[A[i]] == X[B[i]]) {
adj[A[i]][1] = {-1, -1};
adj[B[i]][3] = {-1, -1};
}
if (Y[A[i]] == Y[B[i]]) {
adj[A[i]][0] = {-1, -1};
adj[B[i]][2] = {-1, -1};
}
}
}
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 |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
9168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
5188 KB |
Output is correct |
2 |
Correct |
157 ms |
9236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
9156 KB |
Output is correct |
2 |
Correct |
119 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
9080 KB |
Output is correct |
2 |
Correct |
140 ms |
30456 KB |
Output is correct |