# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577503 | definitelynotmee | Simurgh (IOI17_simurgh) | C++98 | 117 ms | 3500 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
const int INF = 1e7;
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
int m = u.size();
matrix<pii> g(n);
for(int i = 0; i < m; i++){
g[u[i]].push_back({v[i],i});
g[v[i]].push_back({u[i],i});
}
vector<int> royal, dfstree;
dfstree.reserve(n);
royal.reserve(n);
vector<int> check(n), tin(n);
int timer = -1;
auto gettree =[&](int id, auto dfs)->void{
check[id] = 1;
tin[id] = ++timer;
for(auto [viz,edge] : g[id]){
if(!check[viz]){
dfstree.push_back(edge);
dfs(viz,dfs);
}
}
};
gettree(0,gettree);
// for(int i : dfstree){
// cout << "->" << u[i] << ' ' << v[i] << '\n';
// }
fill(all(check),0);
auto test =[&](int id, int remove){
vector<int> query = dfstree;
for(int& i : query){
if(i == remove){
i = id;
break;
}
}
return count_common_roads(query);
};
auto dfs =[&](int id, int last, auto dfs)->pii{
check[id] = 1;
pii back = {INF,0};
for(auto [viz,edge] : g[id]){
if(!check[viz]){
back = min(back,dfs(viz,edge,dfs));
}
}
if(last == -1)
return {0,0};
int resp = back.ff >= tin[id] ? 0 : test(back.ss,last);
vector<int> child(g[id].size());
for(int i = 0; i < g[id].size(); i++){
int viz = g[id][i].ff, edge = g[id][i].ss;
if(tin[viz] > tin[id])
continue;
child[i] = test(edge,last);
resp = max(resp,child[i]);
}
for(int i = 0; i < g[id].size(); i++){
int viz = g[id][i].ff, edge = g[id][i].ss;
if(tin[viz] > tin[id])
continue;
if(child[i] == resp){
back = min(back,{tin[viz],edge});
royal.push_back(edge);
}
}
return back;
};
dfs(0,-1,dfs);
return royal;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |