# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
351181 |
2021-01-19T14:15:19 Z |
minoum |
Flood (IOI07_flood) |
C++17 |
|
2000 ms |
45888 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAXN = 4e5 + 10;
int n, m, h[MAXN];
vector <pair<int,int>> pt, adj[MAXN], ofo, amo, w, all[MAXN]; //ofo=y,amo=x
queue <int> q;
bool inq[MAXN];
inline void addedge(){
for(int i = 0; i < n; i++){
if(all[i].empty()) continue;
sort(all[i].begin(), all[i].end()); all[i].push_back(all[i][0]);
/*cout << "i:" << i+1 << '\n';
for(auto j: all[i]) cout << j.first << ":" << j.second << " ";
cout << endl << endl;*/
for(int j = 0; j < (int)all[i].size()-1; j++){
int id = all[i][j].second, di = all[i][j].first, id2 = all[i][j+1].second, di2 = all[i][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});
}
}
}*/
h[r] = 0; q.push(r); inq[r] = true;
while(!q.empty()){
int v = q.front(); q.pop(); inq[v] = false;
for(auto i: adj[v]){
int u = i.first, ww = i.second;
if(h[u] > h[v]+ww){
h[u] = h[v]+ww;
if(!inq[u]) q.push(u);
inq[u] = true;
}
}
}
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});
}
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);
all[u].push_back({2,i});
all[v].push_back({0,i});
}
else{
ofo.push_back({pt[u].second,i});
if(pt[u].first > pt[v].first) swap(u,v);
all[u].push_back({1,i});
all[v].push_back({3,i});
}
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 |
13 ms |
20716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
20716 KB |
Output is correct |
2 |
Correct |
13 ms |
20716 KB |
Output is correct |
3 |
Correct |
13 ms |
20716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
20716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
20716 KB |
Output is correct |
2 |
Correct |
14 ms |
20844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
20716 KB |
Output is correct |
2 |
Correct |
14 ms |
20864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
20800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
20848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
20716 KB |
Output is correct |
2 |
Correct |
14 ms |
20844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
20844 KB |
Output is correct |
2 |
Correct |
14 ms |
20844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
24944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
109 ms |
36712 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
137 ms |
37608 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1775 ms |
43508 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2081 ms |
45888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |