#include <bits/stdc++.h>
#define ll long long
#define db long double
#define N 400005
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
using namespace std;
struct edge { int num; short int type; };
vector <edge> edge_to_point[100005],angle_to_angle[N];
struct point { int x,y; } a[100005];
pair <int,int> e[N];
int n,m,i,u,v,nangle,f[N],visited[100005],mx[100005],ok,alone[100005];
vector <int> point_to_point[100005],angle_to_side[100005][2],res;
int main()
{
// freopen("flood.inp","r",stdin);
// freopen("flood.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n;
for(i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
cin>>m;
for(i=1;i<=m;i++)
{
cin>>u>>v;
if(a[u].x>a[v].x || (a[u].x==a[v].x && a[u].y>a[v].y)) swap(u,v);
e[i]={ u,v };
point_to_point[u].push_back(v);
point_to_point[v].push_back(u);
if(a[v].x>a[u].x) edge_to_point[u].push_back({ i,2 }),edge_to_point[v].push_back({ i,4 });
if(a[v].y>a[u].y) edge_to_point[u].push_back({ i,1 }),edge_to_point[v].push_back({ i,3 });
}
for(u=1;u<=n;u++)
{
sort(edge_to_point[u].begin(),edge_to_point[u].end(),[&](edge a,edge b){ return a.type<b.type; });
if(edge_to_point[u].size()==0) continue;
else if(edge_to_point[u].size()==1)
{
edge x=edge_to_point[u].back();
alone[u]=++nangle;
for(i=0;i<=1;i++)
angle_to_side[x.num][i].push_back(nangle);
}
else
{
auto consider=[&](edge a,edge b)
{
int oka=(a.type==1 || a.type==4),okb=(b.type==2 || b.type==3);
nangle++;
angle_to_side[a.num][oka].push_back(nangle);
angle_to_side[b.num][okb].push_back(nangle);
};
for(i=1;i<edge_to_point[u].size();i++)
consider(edge_to_point[u][i-1],edge_to_point[u][i]);
consider(edge_to_point[u].back(),edge_to_point[u][0]);
}
}
for(i=1;i<=m;i++)
{
for(ok=0;ok<=1;ok++)
{
u=angle_to_side[i][ok][0],v=angle_to_side[i][ok][1];
angle_to_angle[u].push_back({ v,0 }),angle_to_angle[v].push_back({ u,0 });
}
u=angle_to_side[i][0][0],v=angle_to_side[i][1][0];
angle_to_angle[u].push_back({ v,1 }),angle_to_angle[v].push_back({ u,1 });
}
auto BFS_point=[&](int u)
{
queue <int> q;
vector <int> node;
int ma=0;
q.push(u); visited[u]=1;
while(q.size()>0)
{
int u=q.front(); q.pop();
ma=max(ma,a[u].x);
node.push_back(u);
for(int v:point_to_point[u])
if(visited[v]==0) q.push(v),visited[v]=1;
}
for(int u:node) mx[u]=ma;
};
for(u=1;u<=n;u++)
if(visited[u]==0) BFS_point(u);
memset(f,63,sizeof(f));
set <II> s;
for(i=1;i<=m;i++)
{
int u=e[i].fst,v=e[i].snd;
if(a[v].x==mx[v])
{
if(a[u].x==a[v].x)
for(int u:angle_to_side[i][1])
s.insert({ 0,u }),f[u]=0;
else if(point_to_point[v].size()==1)
s.insert({ 0,alone[v] }),f[alone[v]]=0;
}
}
while(s.size()>0)
{
int u=s.begin()->snd; s.erase(s.begin());
for(edge x:angle_to_angle[u])
{
int v=x.num,k=x.type;
if(f[v]>f[u]+k)
{
s.erase({ f[v],v });
f[v]=f[u]+k;
s.insert({ f[v],v });
}
}
}
for(i=1;i<=m;i++)
{
int u=angle_to_side[i][0][0],v=angle_to_side[i][1][0];
if(f[u]==f[v]) res.push_back(i);
}
cout<<res.size()<<'\n';
for(int x:res) cout<<x<<'\n';
}
Compilation message
flood.cpp: In function 'int main()':
flood.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(i=1;i<edge_to_point[u].size();i++)
| ~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
23640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23632 KB |
Output is correct |
2 |
Correct |
5 ms |
23640 KB |
Output is correct |
3 |
Correct |
5 ms |
23644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23644 KB |
Output is correct |
2 |
Correct |
6 ms |
23896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23896 KB |
Output is correct |
2 |
Correct |
5 ms |
23644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
23644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23900 KB |
Output is correct |
2 |
Correct |
5 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23900 KB |
Output is correct |
2 |
Correct |
5 ms |
23848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
29076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
97 ms |
44456 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
106 ms |
48976 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
250 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
209 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |