# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134477 | 2019-07-22T18:58:19 Z | dragonslayerit | Flood (IOI07_flood) | C++14 | 218 ms | 22196 KB |
#include <cstdio> #include <tuple> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <cassert> const int INF=1e9+7; const double PI=4*atan(1); struct Point{ int x,y; Point():x(0),y(0){ } Point(int x,int y):x(x),y(y){ } void read(){ scanf("%d %d",&x,&y); } bool operator<(Point p)const{ return std::tie(y,x)<std::tie(p.y,p.x); } Point operator-(Point p)const{ return Point(x-p.x,y-p.y); } double arg()const{ double res=std::atan2(y,x); if(res<0) res+=2*PI; return res; } }ps[100005]; int elist[400005]; std::vector<int> adj[400005]; int next[400005]; std::vector<int> dual[100005]; int* cc=elist; int cc_cnt=0; int dist[100005]; int q[100005]; int qh=0,qt=0; int main(){ int N; scanf("%d",&N); for(int i=0;i<N;i++){ ps[i].read(); } int W; scanf("%d",&W); for(int i=0;i<W;i++){ int A,B; scanf("%d %d",&A,&B); A--,B--; elist[i*2]=A; elist[i*2+1]=B; adj[A].push_back(i*2+1); adj[B].push_back(i*2); } for(int i=0;i<N;i++){ std::sort(adj[i].begin(),adj[i].end(),[i](int x,int y){ return (ps[elist[x]]-ps[i]).arg()< (ps[elist[y]]-ps[i]).arg();}); for(int j=0;j<adj[i].size();j++){ int k=(j+1)%adj[i].size(); next[adj[i][j]]=adj[i][k]^1; } } //elist expires //cc begins std::fill(cc,cc+W*2,-1); for(int i=0;i<W*2;i++){ if(cc[i]==-1){ for(int x=i;cc[x]==-1;x=next[x]){ cc[x]=cc_cnt; } cc_cnt++; } } //printf("DUAL: %d vertices\n",cc_cnt); for(int i=0;i<W*2;i++){ //printf("%d => %d: %d => %d\n",a+1,b+1,cc[i],cc[i^1]); dual[cc[i]].push_back(cc[i^1]); } for(int i=0;i<N;i++){ ps[i].x=i; } std::sort(ps,ps+N); //std::queue<int> q; std::fill(dist,dist+N,INF); for(int i=0;i<N;i++){ if(adj[ps[i].x].empty()) continue; int root=cc[adj[ps[i].x][0]^1]; if(dist[root]!=INF) continue; //printf("Root=%d\n",root); q[qh++]=root; //q.push(root); dist[root]=0; // while(!q.empty()){ while(qh!=qt){ int x=q[qt++];//q.front(); //q.pop(); for(int y:dual[x]){ if(dist[y]==INF){ dist[y]=dist[x]+1; //q.push(y); q[qh++]=y; } } } } int survive=0; for(int i=0;i<W;i++){ if(dist[cc[i*2]]==dist[cc[i*2+1]]){ survive++; } } printf("%d\n",survive); for(int i=0;i<W;i++){ if(dist[cc[i*2]]==dist[cc[i*2+1]]){ printf("%d\n",i+1); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12920 KB | Output is correct |
2 | Correct | 13 ms | 12920 KB | Output is correct |
3 | Correct | 13 ms | 12920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12920 KB | Output is correct |
2 | Correct | 13 ms | 12920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12792 KB | Output is correct |
2 | Correct | 13 ms | 12920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12924 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12916 KB | Output is correct |
2 | Correct | 15 ms | 12920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12920 KB | Output is correct |
2 | Correct | 13 ms | 12896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 14328 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 88 ms | 18168 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 94 ms | 18944 KB | Output is correct |
2 | Correct | 218 ms | 21460 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 177 ms | 20572 KB | Output is correct |
2 | Correct | 217 ms | 22196 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 209 ms | 21368 KB | Output is correct |
2 | Correct | 134 ms | 19436 KB | Output is correct |