# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
121318 | TadijaSebez | Flood (IOI07_flood) | C++11 | 355 ms | 14324 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
const int N=200050;
struct pt{ int x,y;pt(){}pt(int a, int b):x(a),y(b){}} P[N];
bool operator < (pt a, pt b){ return mp(a.x,a.y)<mp(b.x,b.y);}
int a[N],b[N],ty[N];
struct seg
{
int id;
seg(int x=0):id(x){}
bool operator < (seg s) const
{
if(P[a[id]].x!=P[a[s.id]].x) return P[a[id]].x<P[a[s.id]].x;
if(ty[id]!=ty[s.id]) return ty[id]<ty[s.id];
return P[a[id]]<P[a[s.id]];
}
};
set<seg> work;
pair<int,int> edge[N][4];
int cnt[N];
int go[4]={3,0,1,2};
int main()
{
int n,w;
scanf("%i",&n);
for(int i=1;i<=n;i++) scanf("%i %i",&P[i].x,&P[i].y);
scanf("%i",&w);
for(int i=1;i<=w;i++)
{
scanf("%i %i",&a[i],&b[i]);
if(P[b[i]]<P[a[i]]) swap(a[i],b[i]);
if(P[a[i]].x==P[b[i]].x)
{
ty[i]=1;
edge[a[i]][0]={i,b[i]};
edge[b[i]][2]={i,a[i]};
}
else
{
ty[i]=2;
edge[a[i]][1]={i,b[i]};
edge[b[i]][3]={i,a[i]};
}
work.insert(seg(i));
}
while(work.size())
{
int x=work.begin()->id;
int fir=a[x],sec=b[x];
vector<int> was;
int u=b[x],mod;
if(ty[x]==1) mod=3;
else mod=0;
while(1)
{
int v;
for(int i=0;i<4;i++)
{
int nm=(mod+i)%4;
if(edge[u][nm].first)
{
cnt[edge[u][nm].first]++;
was.pb(edge[u][nm].first);
v=edge[u][nm].second;
mod=go[nm];
break;
}
}
if(u==fir && v==sec) break;
u=v;
}
sort(was.begin(),was.end());
was.erase(unique(was.begin(),was.end()),was.end());
for(int id:was)
{
if(ty[id]==1)
{
edge[a[id]][0]={0,0};
edge[b[id]][2]={0,0};
}
else
{
edge[a[id]][1]={0,0};
edge[b[id]][3]={0,0};
}
work.erase(seg(id));
}
}
vector<int> ans;
for(int i=1;i<=w;i++) if(cnt[i]==2) ans.pb(i);
printf("%i\n",ans.size());
for(int i:ans) printf("%i\n",i);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |