///breaker
///every second counts
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ii pair<int,int>
#define mp make_pair
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define bit(x,i) ((x>>i)&1)
#define lc (id<<1)
#define rc ((id<<1)^1)
const int maxn=1e5+7;
int x[maxn],y[maxn];
int side[maxn][4][2];
int lev[maxn*4];
int vst[maxn*4];
vector<int>adj[4*maxn];
int w;
int n;
void ghep(int x,int y)
{
adj[x].push_back(y);
adj[y].push_back(x);
}
set<int>s;
void sol(void){
cin>>n;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
cin>>w;
for(int i=1;i<=w;i++){
int a,b;
cin>>a>>b;
if(x[a]==x[b]){
if(y[a]>y[b])swap(a,b);
side[a][2][1]=i;
side[a][2][0]=i+w;
side[b][0][0]=i;
side[b][0][1]=i+w;
s.insert(i);
}
else{
if(x[a]>x[b])swap(a,b);
side[a][1][0]=i;
side[a][1][1]=i+w;
side[b][3][1]=i;
side[b][3][0]=i+w;
}
}
for(int i=1;i<=n;i++){
for(int j=0;j<4;j++)if(side[i][j][1]){
for(int k=(j+1)%4;;k=(k+1)%4)if(side[i][k][0]){
ghep(side[i][j][1],side[i][k][0]);
break;
}
}
}
for(int i=1;i<=w;i++){
lev[i]=lev[i+w]=1e9+7;
}
while(1){
if(s.empty())break;
int tmp=*s.begin();
s.erase(s.begin());
deque<int>q;
q.push_front(tmp);
lev[tmp]=0;
while(q.size()){
int x=q.front();
q.pop_front();
if(vst[x])continue;
s.erase(x);
vst[x]=1;
for(int y:adj[x]){
if(lev[y]>lev[x]){
lev[y]=lev[x];
q.push_front(y);
}
}
adj[x].clear();
int k=(x>w?x-w:x+w);
if(lev[k]>lev[x]+1){
lev[k]=lev[x]+1;
q.push_back(k);
}
}
}
vector<int>ans;
for(int i=1;i<=w;i++){
if(lev[i]==lev[i+w]){
ans.push_back(i);
}
}
cout<<ans.size()<<"\n";
for(int x:ans){
cout<<x<<"\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
while(t--){
sol();
}
// you should actually read the stuff at the bottom
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
14940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
14940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
15008 KB |
Output is correct |
2 |
Correct |
2 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14940 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
14936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Correct |
3 ms |
15028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Correct |
2 ms |
14996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
17496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
25480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
46 ms |
26448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
106 ms |
30032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
130 ms |
32336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |