This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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 = 2e5 + 5;
const double eps = 1e-9;
int x[MAXN], y[MAXN], a[MAXN], b[MAXN], nxt[MAXN][4], vis[MAXN], mrk[MAXN][2];
/*
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 (stderr)
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:48:2: note: in expansion of macro 'ni'
ni(n);
^~
flood.cpp:50: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:51:2: note: in expansion of macro 'ni'
ni(w);
^~
flood.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &u, &v);
~~~~~^~~~~~~~~~~~~~~~~
# | 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... |