#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
struct pt{ ll x,y;pt(){}pt(ll a, ll b):x(a),y(b){}};
bool operator < (pt a, pt b){ return mp(a.x,a.y)<mp(b.x,b.y);}
pt operator - (pt a, pt b){ return pt(a.x-b.x,a.y-b.y);}
ll cross(pt a, pt b){ return a.x*b.y-a.y*b.x;}
const int N=400050;
const int inf=1e9+7;
vector<pair<int,int>> E[N];
pt pts[N];
int u[N],v[N];
int was[N];
vector<int> G[N];
void Find(int x, int y, int e, int bl)
{
was[e]=bl;
vector<pair<int,int>> tmp;
for(auto p:E[y]) tmp.pb(p);
if(tmp.empty()) return;
sort(tmp.begin(),tmp.end(),[&](pair<int,int> a, pair<int,int> b)
{
if(a.first==x) return false;
if(b.first==x) return true;
return cross(pts[a.first]-pts[x],pts[b.first]-pts[x])<0;
});
if(was[tmp[0].second]) return;
Find(y,tmp[0].first,tmp[0].second,bl);
}
void AddEdge(int u, int v){ G[u].pb(v);G[v].pb(u);}
int dist[N];
bool vis[N];
void BFS(int out)
{
queue<int> q;
vis[out]=1;
dist[out]=1;
q.push(out);
while(q.size())
{
int u=q.front();
q.pop();
for(int v:G[u])
{
if(!vis[v])
{
vis[v]=1;
dist[v]=dist[u]+1;
q.push(v);
}
}
}
}
int main()
{
int n,m,i;
scanf("%i",&n);
for(i=1;i<=n;i++) scanf("%lld %lld",&pts[i].x,&pts[i].y);
scanf("%i",&m);
for(i=1;i<=m;i++)
{
scanf("%i %i",&u[i],&v[i]);
E[u[i]].pb({v[i],i<<1});
E[v[i]].pb({u[i],i<<1|1});
}
int block=0;
for(i=2;i<=(m<<1|1);i++) if(!was[i])
{
block++;
if(i&1) Find(v[i>>1],u[i>>1],i,block);
else Find(u[i>>1],v[i>>1],i,block);
}
for(i=1;i<=block;i++) dist[i]=inf,vis[i]=0;
vector<int> ver;
vector<int> hor;
for(i=1;i<=m;i++)
{
AddEdge(was[i<<1],was[i<<1|1]);
if(pts[u[i]].y==pts[v[i]].y) ver.pb(i);
else hor.pb(i);
}
sort(ver.begin(),ver.end(),[&](int x, int y){ return pts[u[x]].x<pts[u[y]].x;});
for(int id:ver)
{
int l;
if(pts[u[id]].y<pts[v[id]].y) l=id<<1;
else l=id<<1|1;
if(!vis[was[l]]) BFS(was[l]);
}
sort(hor.begin(),hor.end(),[&](int x, int y){ return pts[u[x]].y<pts[u[y]].y;});
for(int id:hor)
{
int l;
if(pts[u[id]].x<pts[v[id]].x) l=id<<1|1;
else l=id<<1;
if(!vis[was[l]]) BFS(was[l]);
}
vector<int> ans;
for(i=1;i<=m;i++)
{
if(dist[was[i<<1]]==dist[was[i<<1|1]]) ans.pb(i);
}
printf("%i\n",ans.size());
for(int a:ans) printf("%i\n",a);
return 0;
}
Compilation message
flood.cpp: In function 'int main()':
flood.cpp:107:26: warning: format '%i' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
printf("%i\n",ans.size());
~~~~~~~~~~^
flood.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
flood.cpp:62:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1;i<=n;i++) scanf("%lld %lld",&pts[i].x,&pts[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flood.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&m);
~~~~~^~~~~~~~~
flood.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&u[i],&v[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
19200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
19192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
19200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
19200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
19172 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
19200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19172 KB |
Output is correct |
2 |
Correct |
18 ms |
19200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19200 KB |
Output is correct |
2 |
Incorrect |
17 ms |
19284 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
21624 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
32616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
29088 KB |
Output is correct |
2 |
Runtime error |
311 ms |
34616 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
232 ms |
32852 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
344 ms |
34372 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |