#include <bits/stdc++.h>
using namespace std;
int n,w,x[100001],y[100001],a[200001],b[200001],dx[4]={1,0,-1,0},dy[4]={0,1,0,-1},p[400001],l[100001];
vector <int> safe;
int f(int i){
return (l[i]==i?i:l[i]=f(l[i]));
}
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n;
vector <int> nxt[n+1][4],ve[n+1];
vector <pair <int, int>> q[n+10];
iota(l,l+n+1,0);
for (int i=1;i<=n;i++)
cin >> x[i] >> y[i];
cin >> w;
for (int i=1;i<=w;i++){
cin >> a[i] >> b[i];
l[f(a[i])]=f(b[i]);
a[i+w]=b[i];
b[i+w]=a[i];
for (int j=0;j<4;j++)
if (abs(dx[j])+abs(x[a[i]]+dx[j]-x[b[i]])==abs(x[a[i]]-x[b[i]])&&abs(dy[j])+abs(y[a[i]]+dy[j]-y[b[i]])==abs(y[a[i]]-y[b[i]])){
nxt[a[i]][j]={i};
nxt[b[i]][(j+2)&3]={i+w};
}
}
for (int i=1;i<=n;i++)
ve[f(i)].push_back(i);
for (int i=1;i<=n;i++){
if (ve[i].empty())
continue;
int mx=0;
for (int j:ve[i])
if (!mx||x[mx]>x[j]||(x[mx]==x[j]&&y[mx]<y[j]))
mx=j;
if (nxt[mx][3].empty())
continue;
q[1].push_back({nxt[mx][3][0],3});
ve[i].clear();
}
for (int i=1;i<n+10;i++)
while (!q[i].empty()){
auto [u,d]=q[i].back();
q[i].pop_back();
if (p[u])
continue;
p[u]=i;
q[i+1].push_back({(u>w?u-w:u+w),(d+2)&3});
int cur=(u>w?a[u-w]:b[u]);
for (int j=0;j<4;j++)
if (!nxt[cur][(d+j+3)%4].empty()){
int v=nxt[cur][(d+j+3)%4][0];
nxt[cur][(d+j+3)%4].clear();
q[i].push_back({v,(d+j+3)%4});
break;
}
}
for (int i=1;i<=w;i++)
if (p[i]==p[i+w])
safe.push_back(i);
cout << safe.size() << '\n';
for (int i:safe)
cout << i << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
3 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
10716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
26136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
28404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
32084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
168 ms |
34336 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |