# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1095366 |
2024-10-02T02:06:15 Z |
doducanh |
Flood (IOI07_flood) |
C++14 |
|
133 ms |
31564 KB |
///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[4*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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14680 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14680 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14680 KB |
Output is correct |
2 |
Correct |
2 ms |
14680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
18904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
24980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
25684 KB |
Output is correct |
2 |
Correct |
133 ms |
31312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
29012 KB |
Output is correct |
2 |
Correct |
124 ms |
31564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
31056 KB |
Output is correct |
2 |
Correct |
44 ms |
25812 KB |
Output is correct |