| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 960966 | Trisanu_Das | Simurgh (IOI17_simurgh) | C++17 | 87 ms | 3796 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>
#define pb emplace_back
#define vi vector<int>
#define pii pair<int,int>
#define fi first
#define se second
#define all(n) (n).begin(),(n).end()
using namespace std;
vi ans, pos, pos2, U, V;
int pa[505], N, M;
void init(){
for(int i=0;i<N;i++) pa[i] = i;
}
int fp(int x){
if(pa[x] == x) return x;
return pa[x] = fp(pa[x]);
}
void uni(int x,int y){
x = fp(x), y = fp(y);
assert(x != y);
pa[x] = y;
}
void search_next(){
init();
int cnt = N;
vi cur;
for(auto &i:ans){
uni(U[i], V[i]);
cur.pb(i);
cnt--;
}
vector<pii> tried;
for(auto &i:pos){
if(cnt == 2){
if(fp(U[i]) != fp(V[i])){
cur.pb(i);
assert(cur.size() == N-1);
int common = count_common_roads(cur);
tried.pb(common,i);
cur.pop_back();
}
else pos2.pb(i);
}
else{
if(fp(U[i]) != fp(V[i])){
cur.pb(i);
uni(U[i], V[i]);
cnt--;
}
pos2.pb(i);
}
}
pair<int,int> mx = *max_element(all(tried));
for(auto &x : tried) if(x.fi == mx.fi) ans.pb(x.se);
swap(pos, pos2);
pos2.clear();
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
M = u.size(), N = n;
U = u, V = v;
for(int i=0;i<M;i++) pos.pb(i);
while(ans.size() < N - 1) search_next();
return ans;
}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... | ||||
