이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
const int dydis = 1e5 + 10;
vector<pair<int, int> > gr[dydis];
int n, m;
long long light, heavy;
int tevas[dydis];
int dist[dydis];
int virs[dydis];
int getLen(){
vector<int> st;
for(int i = 0; i < m; i++) st.push_back(0);
return 1ll * ask(st) / light;
}
void dfs(int v, int came = -1, int dst = 0){
dist[v] = dst;
for(auto x : gr[v]){
if(x.first == came) continue;
tevas[x.first] = v;
virs[x.first] = x.second;
dfs(x.first, v, dst+1);
}
}
vector<pair<int, int> > getInds(int v, int len){ // first - brianos indeksas, sec - virsunes
dfs(v, -1);
vector<pair<int, int> > ret;
for(int i = 0; i < n; i++){
if(dist[i] != len) continue;
ret.push_back({virs[i], i});
}
return ret;
}
pair<int, int> solveWhenHave(int v, int len){
vector<pair<int, int> > inds = getInds(v, len); // cia turetu visi buti blogi, isskyrus viena!
int l = 0; int r = inds.size()-1; int mid = -1; int kair = inds.size()-1;
vector<int> askk(m, 0);
long long turi = len * light;
while(l <= r){
mid = (l + r) / 2;
for(int i = 0; i <= mid; i++) askk[inds[i].first] = 1;
if(ask(askk) != turi){
r = mid-1;
kair = min(kair, mid);
}else{
l = mid+1;
}
for(int i = 0; i <= mid; i++) askk[inds[i].first] = 0;
}
return {v, inds[kair].second};
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
n = N;
m = V.size();
light = A; heavy = B;
for(int i = 0; i < m; i++){
gr[U[i]].push_back({V[i], i});
gr[V[i]].push_back({U[i], i});
}
int len = getLen();
auto ans = solveWhenHave(0, len);
answer(ans.first, ans.second);
return ;
}
/*
12 11 5 7 0 10
0 2
0 3
2 4
2 5
3 6
3 7
4 8
5 9
8 10
8 11
9 1
*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |