# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
456333 |
2021-08-06T13:11:47 Z |
dutch |
Flood (IOI07_flood) |
C++17 |
|
231 ms |
25640 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+1, M = N+N, INF = 1e9;
int n, m, x[N], y[N], a[M], b[M], up[N], dn[N], lf[N], rt[N], d[M*2];
bool vertical[M], vis[M*2];
vector<int> g[M*2], ans;
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1; i<=n; ++i)
cin >> x[i] >> y[i];
cin >> m;
for(int i=1; i<=m; ++i){
int &u = a[i], &v = b[i];
cin >> u >> v;
if((vertical[i] = (x[u] == x[v]))){
if(y[u] > y[v]) swap(u, v);
up[u] = dn[v] = i;
}else{
if(x[u] > x[v]) swap(u, v);
rt[u] = lf[v] = i;
}
}
vis[0] = 1;
for(int i=1; i<=m+m; ++i){
int u = i, v;
while(!vis[u]){
vis[u] = !(v = 0);
int w = u;
if(vertical[((u-1) % m) + 1]){
if(u > m){ // right
u -= m;
if(rt[a[u]] && !v) v = rt[a[u]] + m;
if(dn[a[u]] && !v) v = dn[a[u]] + m;
if(lf[a[u]] && !v) v = lf[a[u]];
if(up[a[u]] && !v) v = up[a[u]];
}else{
if(lf[b[u]] && !v) v = lf[b[u]];
if(up[b[u]] && !v) v = up[b[u]];
if(rt[b[u]] && !v) v = rt[b[u]] + m;
if(dn[b[u]] && !v) v = dn[b[u]] + m;
}
}else{
if(u > m){ // up
u -= m;
if(up[b[u]] && !v) v = up[b[u]];
if(rt[b[u]] && !v) v = rt[b[u]] + m;
if(dn[b[u]] && !v) v = dn[b[u]] + m;
if(lf[b[u]] && !v) v = lf[b[u]];
}else{
if(dn[a[u]] && !v) v = dn[a[u]] + m;
if(lf[a[u]] && !v) v = lf[a[u]];
if(up[a[u]] && !v) v = up[a[u]];
if(rt[a[u]] && !v) v = rt[a[u]] + m;
}
}
if(v){
g[w].push_back(v);
g[v].push_back(w);
}
u = v;
}
}
deque<int> q;
array<int, 2> todo[m+1]; int p = 1;
for(int i=1; i<=m; ++i)
todo[i] = {vertical[i] ? x[a[i]] : y[a[i]], i};
fill(d, d+m+m+1, INF);
while(p <= m){
q.push_back(todo[p][1]);
d[todo[p][1]] = 0;
while(!q.empty()){
int u = q.front(); q.pop_front();
for(int v : g[u]) if(d[v] > d[u]){
d[v] = d[u];
q.push_front(v);
}
int v = u > m ? u-m : u+m;
if(d[v] > d[u] + 1){
d[v] = d[u] + 1;
q.push_back(v);
}
if(d[u] == d[v]) ans.push_back(min(u, v));
}
while(p<=m && d[todo[p][1]] < INF) ++p;
}
sort(begin(ans), end(ans));
ans.resize(unique(begin(ans), end(ans)) - begin(ans));
cout << size(ans) << '\n';
for(int i : ans) cout << i << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Correct |
5 ms |
9676 KB |
Output is correct |
3 |
Correct |
6 ms |
9772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9676 KB |
Output is correct |
2 |
Incorrect |
7 ms |
9676 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9744 KB |
Output is correct |
2 |
Correct |
6 ms |
9828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9804 KB |
Output is correct |
2 |
Correct |
6 ms |
9804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
19496 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
19848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
172 ms |
23884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
231 ms |
25640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |