#include <bits/stdc++.h>
#include <iostream>
#define F first
#define S second
using namespace std;
const int N=200005;
int n,m,ko,X;
int x[N],y[N],a[N],b[N],f[N],F[N];
pair < int , pair < int , int > > Up[N],Left[N],Down[N],Right[N];
vector < int > ANS;
set <pair < pair < int , int > , int > > st;
void Dfs (int idx,int idxedge,int p) {
if (f[idxedge]==X) { ko=1; return; } f[idxedge]=X;
if (F[idxedge]) return ; F[idxedge]=1;
st.erase(st.find({{x[b[idxedge]],y[a[idxedge]]},idxedge}));
if (p==3) {
if (Left[idx].F) { Dfs(Left[idx].S.F,Left[idx].S.S,0); if (ko) return ; }
if (Up[idx].F) { Dfs(Up[idx].S.F,Up[idx].S.S,3); if (ko) return ; }
if (Right[idx].F) { Dfs(Right[idx].S.F,Right[idx].S.S,2); if (ko) return ; }
ANS.push_back(idxedge);
}
else
if (p==2) {
if (Up[idx].F) { Dfs(Up[idx].S.F,Up[idx].S.S,3); if (ko) return ; }
if (Right[idx].F) { Dfs(Right[idx].S.F,Right[idx].S.S,2); if (ko) return ; }
if (Down[idx].F) { Dfs(Down[idx].S.F,Down[idx].S.S,1); if (ko) return ; }
ANS.push_back(idxedge);
}
else
if (p==1) {
if (Right[idx].F) { Dfs(Right[idx].S.F,Right[idx].S.S,2); if (ko) return ; }
if (Down[idx].F) { Dfs(Down[idx].S.F,Down[idx].S.S,1); if (ko) return ; }
if (Left[idx].F) { Dfs(Left[idx].S.F,Left[idx].S.S,0); if (ko) return ; }
ANS.push_back(idxedge);
}
else
if (!p) {
if (Down[idx].F) { Dfs(Down[idx].S.F,Down[idx].S.S,1); if (ko) return ; }
if (Left[idx].F) { Dfs(Left[idx].S.F,Left[idx].S.S,0); if (ko) return ; }
if (Up[idx].F) { Dfs(Up[idx].S.F,Up[idx].S.S,3); if (ko) return ; }
ANS.push_back(idxedge);
}
}
main () {
scanf("%d",&n);
for (int i=1; i<=n; i++)
scanf("%d %d",&y[i],&x[i]);
scanf("%d",&m);
for (int i=1; i<=m; i++) {
scanf("%d %d",&a[i],&b[i]);
if (y[a[i]]>y[b[i]]) swap(a[i],b[i]);
if (x[a[i]]<x[b[i]]) swap(a[i],b[i]);
if (x[a[i]]==x[b[i]]) {
Left[b[i]].F=1,Left[b[i]].S.F=a[i],Left[b[i]].S.S=i;
Right[a[i]].F=1,Right[a[i]].S.F=b[i],Right[a[i]].S.S=i;
}
else {
Up[b[i]].F=1,Up[b[i]].S.F=a[i],Up[b[i]].S.S=i;
Down[a[i]].F=1,Down[a[i]].S.F=b[i],Down[a[i]].S.S=i;
}
st.insert({{x[b[i]],y[a[i]]},i});
}
while (st.size()) {
int stedge=(*st.begin()).S;
ko=0;
++X;
if (x[a[stedge]]==x[b[stedge]]) Dfs(a[stedge],stedge,0);
else Dfs(a[stedge],stedge,3);
}
printf("%d\n",ANS.size());
for (int i=0; i<ANS.size(); i++)
printf("%d\n",ANS[i]);
}
Compilation message
flood.cpp:47:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
flood.cpp: In function 'int main()':
flood.cpp:80:26: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
printf("%d\n",ANS.size());
~~~~~~~~~~^
flood.cpp:82:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<ANS.size(); i++)
~^~~~~~~~~~~
flood.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&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",&y[i],&x[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
flood.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&m);
~~~~~^~~~~~~~~
flood.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a[i],&b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
3964 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
84 ms |
14540 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
104 ms |
14624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
241 ms |
18660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
292 ms |
20472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |