# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073708 | 2024-08-24T18:52:13 Z | vjudge1 | Simurgh (IOI17_simurgh) | C++17 | 182 ms | 460 KB |
#include "simurgh.h" #include <bits/stdc++.h> using namespace std; vector<vector<pair<int,int>>>adj(505); vector<vector<int>>adj1(505); vector<bool> vis(505,0); void DFS(int n){ vis[n] = 1; for(auto x: adj1[n]){ if(vis[x])continue; DFS(x); } } vector<int> find_roads(int n, vector<int> u, vector<int> v) { vector<pair<int,int>> edges; vector<int> r; int res=0; for(int i=0; i < u.size(); i++){ edges.push_back({u[i],v[i]}); adj[u[i]].push_back({v[i],i}); adj[v[i]].push_back({u[i],i}); } for(auto [x,y]: adj[0]){ r.push_back(y); //cout<<y<<" "; } //cout<<endl; int pos=0, lastres = 0, last = 0; if(edges.size() == (n*(n-1))/2 && n > 7){ vector<bool> used(edges.size(),0); for(auto x: r){ used[x] = 1; } res = count_common_roads(r); while(pos < n-1 && res < n-1){ for(auto [x,y]: adj[edges[r[pos]].second]){ if(!used[y]){ last = r[pos]; r[pos] = y; used[y] = 1; break; } } lastres = res; res = count_common_roads(r); /*for(auto x: r){ cout<<x<<" "; } cout<<endl;*/ if(lastres < res){ pos++; }else if(lastres == res){ for(auto [x,y]: adj[edges[r[pos]].first]){ used[y] = 1; } for(auto [x,y]: adj[edges[r[pos]].second]){ used[y] = 1; } used[r[pos]] = 0; r[pos] = last; pos++; res = lastres; }else if(lastres > res){ r[pos] = last; pos++; res = lastres; } } return r; } for(int b=0; b < (1<<edges.size()); b++){ r.clear(); for(int i=0; i < n; i++){ adj1[i].clear(); vis[i] = 0; } for(int i=0; i < edges.size(); i++){ if(b & (1<<i)){ adj1[edges[i].first].push_back(edges[i].second); adj1[edges[i].second].push_back(edges[i].first); r.push_back(i); } } if(r.size() != n-1){ continue; } DFS(0); int cnt = 0; for(int i=0; i < n; i++){ if(vis[i]){ cnt++; }else{ break; } } if(cnt == n){ res = count_common_roads(r); }else{ continue; } if(res == n-1){ return r; } } return {0}; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 344 KB | correct |
2 | Correct | 143 ms | 344 KB | correct |
3 | Correct | 182 ms | 432 KB | correct |
4 | Correct | 1 ms | 348 KB | correct |
5 | Correct | 0 ms | 460 KB | correct |
6 | Correct | 4 ms | 460 KB | correct |
7 | Correct | 0 ms | 348 KB | correct |
8 | Correct | 1 ms | 348 KB | correct |
9 | Correct | 0 ms | 460 KB | correct |
10 | Correct | 1 ms | 344 KB | correct |
11 | Correct | 0 ms | 348 KB | correct |
12 | Correct | 2 ms | 344 KB | correct |
13 | Correct | 46 ms | 348 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 344 KB | correct |
2 | Correct | 143 ms | 344 KB | correct |
3 | Correct | 182 ms | 432 KB | correct |
4 | Correct | 1 ms | 348 KB | correct |
5 | Correct | 0 ms | 460 KB | correct |
6 | Correct | 4 ms | 460 KB | correct |
7 | Correct | 0 ms | 348 KB | correct |
8 | Correct | 1 ms | 348 KB | correct |
9 | Correct | 0 ms | 460 KB | correct |
10 | Correct | 1 ms | 344 KB | correct |
11 | Correct | 0 ms | 348 KB | correct |
12 | Correct | 2 ms | 344 KB | correct |
13 | Correct | 46 ms | 348 KB | correct |
14 | Incorrect | 1 ms | 348 KB | WA in grader: NO |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 344 KB | correct |
2 | Correct | 143 ms | 344 KB | correct |
3 | Correct | 182 ms | 432 KB | correct |
4 | Correct | 1 ms | 348 KB | correct |
5 | Correct | 0 ms | 460 KB | correct |
6 | Correct | 4 ms | 460 KB | correct |
7 | Correct | 0 ms | 348 KB | correct |
8 | Correct | 1 ms | 348 KB | correct |
9 | Correct | 0 ms | 460 KB | correct |
10 | Correct | 1 ms | 344 KB | correct |
11 | Correct | 0 ms | 348 KB | correct |
12 | Correct | 2 ms | 344 KB | correct |
13 | Correct | 46 ms | 348 KB | correct |
14 | Incorrect | 1 ms | 348 KB | WA in grader: NO |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | correct |
2 | Incorrect | 0 ms | 348 KB | WA in grader: NO |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 344 KB | correct |
2 | Correct | 143 ms | 344 KB | correct |
3 | Correct | 182 ms | 432 KB | correct |
4 | Correct | 1 ms | 348 KB | correct |
5 | Correct | 0 ms | 460 KB | correct |
6 | Correct | 4 ms | 460 KB | correct |
7 | Correct | 0 ms | 348 KB | correct |
8 | Correct | 1 ms | 348 KB | correct |
9 | Correct | 0 ms | 460 KB | correct |
10 | Correct | 1 ms | 344 KB | correct |
11 | Correct | 0 ms | 348 KB | correct |
12 | Correct | 2 ms | 344 KB | correct |
13 | Correct | 46 ms | 348 KB | correct |
14 | Incorrect | 1 ms | 348 KB | WA in grader: NO |
15 | Halted | 0 ms | 0 KB | - |