제출 #1095367

#제출 시각아이디문제언어결과실행 시간메모리
1095367doducanhFlood (IOI07_flood)C++14
100 / 100
130 ms30688 KiB
///breaker ///every second counts #pragma GCC optimize("O2") #include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define ii pair<int,int> #define mp make_pair #define in(x) freopen(x,"r",stdin) #define out(x) freopen(x,"w",stdout) #define bit(x,i) ((x>>i)&1) #define lc (id<<1) #define rc ((id<<1)^1) const int maxn=1e5+7; int x[maxn],y[maxn]; int side[maxn][4][2]; int lev[maxn*4]; int vst[maxn*4]; vector<int>adj[4*maxn]; int xof[2*maxn]; int w; int n; void ghep(int x,int y) { adj[x].push_back(y); adj[y].push_back(x); } set<ii>s; void sol(void){ cin>>n; for(int i=1;i<=n;i++){ cin>>x[i]>>y[i]; } cin>>w; for(int i=1;i<=w;i++){ int a,b; cin>>a>>b; if(x[a]==x[b]){ if(y[a]>y[b])swap(a,b); side[a][2][1]=i; side[a][2][0]=i+w; side[b][0][0]=i; side[b][0][1]=i+w; xof[i]=x[a]; s.insert({xof[i],i}); } else{ if(x[a]>x[b])swap(a,b); side[a][1][0]=i; side[a][1][1]=i+w; side[b][3][1]=i; side[b][3][0]=i+w; xof[i]=1e9+7; } } for(int i=1;i<=n;i++){ for(int j=0;j<4;j++)if(side[i][j][1]){ for(int k=(j+1)%4;;k=(k+1)%4)if(side[i][k][0]){ ghep(side[i][j][1],side[i][k][0]); break; } } } for(int i=1;i<=w;i++){ lev[i]=lev[i+w]=1e9+7; } while(1){ if(s.empty())break; int tmp=s.begin()->se; deque<int>q; q.push_front(tmp); lev[tmp]=0; while(q.size()){ int x=q.front(); q.pop_front(); if(vst[x])continue; if(x<=w)s.erase({xof[x],x}); vst[x]=1; for(int y:adj[x]){ if(lev[y]>lev[x]){ lev[y]=lev[x]; q.push_front(y); } } adj[x].clear(); int k=(x>w?x-w:x+w); if(lev[k]>lev[x]+1){ lev[k]=lev[x]+1; q.push_back(k); } } } vector<int>ans; for(int i=1;i<=w;i++){ if(lev[i]==lev[i+w]){ ans.push_back(i); } } cout<<ans.size()<<"\n"; for(int x:ans){ cout<<x<<"\n"; } } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t=1; while(t--){ sol(); } // you should actually read the stuff at the bottom return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...