//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
int x[MAXN], y[MAXN], a[MAXN], b[MAXN], nxt[MAXN][4], vis[MAXN], mrk[MAXN][2];
vii adj[MAXN];
/*
3
2 0
1
*/
int main() {
priority_queue<pair<pii,int>> pq;
int n, w;
ni(n);
for (int i = 1; i <= n; i++)
scanf("%d %d", x + i, y + i);
ni(w);
for (int i = 1; i <= w; i++) {
int u, v;
scanf("%d %d", &u, &v);
if (x[u] > x[v] || y[u] > y[v])
swap(u, v);
a[i] = u, b[i] = v;
if (x[u] == x[v]) { // vertical
nxt[u][3] = i;
nxt[v][1] = i;
} else { // horizontal
nxt[u][0] = i;
nxt[v][2] = i;
}
pq.push(mp(mp(x[v], -y[v]), i));
}
while (!pq.empty()) {
int cur = pq.top().se; pq.pop();
if (vis[cur])
continue;
int u = a[cur], dir = x[a[cur]] == x[b[cur]] ? 1 : 2;
vi act;
while (1) {
int nx, ndir;
for (int i = 0; i < 4; i++) {
ndir = (dir + 3 + i) % 4;
nx = nxt[u][ndir];
if (nx > 0 && !vis[nx])
break;
}
if (mrk[nx][ndir / 2])
break;
mrk[nx][ndir / 2] = 1;
act.pb(nx);
if (a[nx] == u)
u = b[nx];
else
u = a[nx];
dir = ndir;
}
for (int nx: act)
vis[nx] = 1;
}
vi ans;
for (int i = 1; i <= w; i++)
if (mrk[i][0] > 0 && mrk[i][1] > 0)
ans.pb(i);
printf("%d\n",(int) ans.size());
for (int i: ans)
printf("%d\n", i);
return 0;
}
Compilation message
flood.cpp: In function 'int main()':
flood.cpp:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ni(n) scanf("%d", &(n))
~~~~~^~~~~~~~~~~~
flood.cpp:49:2: note: in expansion of macro 'ni'
ni(n);
^~
flood.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", x + i, y + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~
flood.cpp:9:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ni(n) scanf("%d", &(n))
~~~~~^~~~~~~~~~~~
flood.cpp:52:2: note: in expansion of macro 'ni'
ni(w);
^~
flood.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &u, &v);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23808 KB |
Output is correct |
2 |
Correct |
22 ms |
23800 KB |
Output is correct |
3 |
Correct |
23 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23936 KB |
Output is correct |
2 |
Correct |
22 ms |
23936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23936 KB |
Output is correct |
2 |
Correct |
21 ms |
23928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
23928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
23936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
24056 KB |
Output is correct |
2 |
Correct |
22 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
25884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
31096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
31144 KB |
Output is correct |
2 |
Runtime error |
163 ms |
34380 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
141 ms |
33512 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
152 ms |
34284 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |