#include<bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;
const int N = 2e5 + 10;
int n, m;
pii c[N][4]; // right, down, left, up
bool vis[N][4], vis2[2*N];
int order[N];
pii pt[N];
int cnt = 0;
vector<int> adj[2*N];
set<int> adj2[2*N];
int dis[2*N];
vector<int> passed;
bool outer = 1;
vector<int> outer_list;
void dfs(int i, int dir) {
for (int j = -1; j <= 2; ++j) {
int cur = (dir+j+4)%4;
if (c[i][cur].st && vis[i][cur]) return;
else if (c[i][cur].st) {
vis[i][cur] = 1;
if (vis2[c[i][cur].nd]) outer = 0;
passed.pb(c[i][cur].nd);
dfs(c[i][cur].st, cur);
adj[c[i][cur].nd].pb(cnt);
return;
}
}
}
bool cmp(int i, int j) {
if (pt[i].nd == pt[j].nd) return pt[i].st < pt[j].st;
return pt[i].nd < pt[j].nd;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> pt[i].st >> pt[i].nd;
cin >> m;
for (int i = 1; i <= m; ++i) {
int a, b; cin >> a >> b;
if (pt[a].st == pt[b].st) {
if (pt[a].nd > pt[b].nd) {
c[a][1].st = b, c[b][3].st = a;
c[a][1].nd = i, c[b][3].nd = i;
}
else {
c[a][3].st = b, c[b][1].st = a;
c[a][3].nd = i, c[b][1].nd = i;
}
}
else {
if (pt[a].st > pt[b].st) {
c[a][2].st = b, c[b][0].st = a;
c[a][2].nd = i, c[b][0].nd = i;
}
else {
c[a][0].st = b, c[b][2].st = a;
c[a][0].nd = i, c[b][2].nd = i;
}
}
}
for (int i = 1; i <= n; ++i) order[i] = i;
sort(order+1, order+n+1, cmp);
int dir = 3;
for (int i = 1; i <= n; ++i) {
for (int j = -1; j <= 2; ++j) {
int cur = (dir+j+4)%4;
if (c[order[i]][cur].st && vis[order[i]][cur]) break;
else if (c[order[i]][cur].st) {
cnt++;
int idx = passed.size();
outer = 1;
dfs(order[i], cur);
for (int k = idx; k < passed.size(); ++k) {
vis2[passed[k]] = 1;
}
if (outer) outer_list.pb(cnt);
break;
}
}
}
for (int i = 1; i <= m; ++i) {
adj2[adj[i][0]].insert(adj[i][1]);
adj2[adj[i][1]].insert(adj[i][0]);
}
queue<int> q;
for (auto i : outer_list) {
q.push(i);
dis[i] = 1;
}
while (!q.empty()) {
int i = q.front(); q.pop();
for (auto j : adj2[i]) {
if (dis[j] == 0) {
dis[j] = dis[i] + 1;
q.push(j);
}
}
}
vector<int> ans;
for (int i = 1; i <= m; ++i) {
if (dis[adj[i][0]] == dis[adj[i][1]]) ans.pb(i);
}
cout << ans.size() << '\n';
for (auto i : ans) cout << i << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Compilation message
flood.cpp: In function 'void solve()':
flood.cpp:87:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int k = idx; k < passed.size(); ++k) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28528 KB |
Output is correct |
2 |
Correct |
14 ms |
28436 KB |
Output is correct |
3 |
Correct |
14 ms |
28456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
28500 KB |
Output is correct |
2 |
Runtime error |
36 ms |
57708 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
40 ms |
57648 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
28584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
28520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
28484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
30868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
103 ms |
65536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
74 ms |
38668 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
142 ms |
65536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
140 ms |
65536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |