# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
351290 |
2021-01-19T21:22:19 Z |
minoum |
Flood (IOI07_flood) |
C++17 |
|
426 ms |
32656 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAXN = 4e5 + 10;
int n, m, h[MAXN], wl[4][MAXN]; //dw[MAXN], up[MAXN], lf[MAXN], ri[MAXN], allw[MAXN];
vector <pair<int,int>> pt, adj[MAXN], ofo, amo, all; //ofo=y,amo=x
inline void addedge(){
for(int i = 0; i < n; i++){
all.clear();
for(int j = 0; j < 4; j++)
if(wl[j][i] != -1) all.push_back({j, wl[j][i]});
if(all.empty()) continue;
sort(all.begin(), all.end()); all.push_back(all[0]);
for(int j = 0; j < (int)all.size()-1; j++){
int id = all[j].second, di = all[j].first, id2 = all[j+1].second, di2 = all[j+1].first;
int t1 = (di==3||di==2), t2 = (di2==3||di2==2); //0->{1,0} 1->{3,2}
if(t1 && !t2){
adj[id].push_back({id2,0});
adj[id2].push_back({id,0});
}
if(t1 && t2){
adj[id].push_back({id2+m,0});
adj[id2+m].push_back({id,0});
}
if(!t1 && !t2){
adj[id+m].push_back({id2,0});
adj[id2].push_back({id+m,0});
}
if(!t1 && t2){
adj[id+m].push_back({id2+m,0});
adj[id2+m].push_back({id+m,0});
}
}
}
for(int i = 0; i < m; i++){
adj[i].push_back({i+m,1});
adj[i+m].push_back({i,1});
}
return;
}
inline void slv(int r){
set <pair<int,int>> st; h[r] = 0;
st.insert({0,r});
while(!st.empty()){
int v = st.begin()->second; st.erase(*st.begin());
for(auto i: adj[v]){
int u = i.first, ww = i.second;
if(h[u] > h[v]+ww){
st.erase({h[u],u});
h[u] = h[v]+ww;
st.insert({h[u],u});
}
}
}
return;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
for(int i = 0; i < MAXN; i++) h[i] = INT_MAX;
cin >> n;
for(int i = 0; i < n; i++){
int xx,yy;
cin >> xx >> yy;
pt.push_back({xx,yy});
// dw[i] = up[i] = lf[i] = ri[i] = -1;
wl[0][i] = wl[1][i] = wl[2][i] = wl[3][i] = -1;
}
cin >> m;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v; u--; v--;
if(pt[u].first==pt[v].first){
amo.push_back({pt[u].first,i});
if(pt[u].second > pt[v].second) swap(u,v);
// dw[u] = i; up[v] = i;
// all[u].push_back({2,i});
// all[v].push_back({0,i});
wl[2][u] = wl[0][v] = i;
}
else{
ofo.push_back({pt[u].second,i});
if(pt[u].first > pt[v].first) swap(u,v);
// ri[u] = i; lf[v] = i;
// all[u].push_back({1,i});
// all[v].push_back({3,i});
wl[1][u] = wl[3][v] = i;
}
// allw[u]++; allw[v]++;
// w.push_back({u,v});
}
addedge();
sort(ofo.begin(), ofo.end());
sort(amo.begin(), amo.end());
for(auto i: ofo)
if(h[i.second] >= INT_MAX) slv(i.second);
for(auto i: amo)
if(h[i.second] >= INT_MAX) slv(i.second);
vector <int> ans;
for(int i = 0; i < m; i++)
if(h[i] == h[i+m]) ans.push_back(i);
cout << (int)ans.size() << '\n';
for(auto i: ans) cout << i+1 <<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11372 KB |
Output is correct |
2 |
Correct |
7 ms |
11192 KB |
Output is correct |
3 |
Correct |
7 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11372 KB |
Output is correct |
2 |
Correct |
8 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11372 KB |
Output is correct |
2 |
Correct |
7 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
11372 KB |
Output is correct |
2 |
Correct |
8 ms |
11500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
11372 KB |
Output is correct |
2 |
Correct |
8 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
14532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
22944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
23016 KB |
Output is correct |
2 |
Correct |
426 ms |
32400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
333 ms |
29556 KB |
Output is correct |
2 |
Correct |
415 ms |
32656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
402 ms |
31864 KB |
Output is correct |
2 |
Correct |
367 ms |
30444 KB |
Output is correct |