이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
const int mx = 90005;
int N, M;
ll A, B;
int D;
vi U, V;
vpi adj[mx]; //node, edge
int getDist(){
vi w(M, 0);
return ask(w)/A;
}
vpi jeds; //edges just before degree d nodes, label of nodes
void findJeds(int node, int d = 0, int prv = -1){
for(auto u: adj[node]){
if(u.f == prv) continue;
if(d+1 == D){
jeds.pb(mp(u.s, u.f));
continue;
}
findJeds(u.f, d+1, node);
}
}
void find_pair(int _N, vi _U, vi _V, int _A, int _B) {
N = _N;
U = _U;
V = _V;
M = sz(U);
for(int i = 0; i < M; i++){
adj[U[i]].pb(mp(V[i], i));
adj[V[i]].pb(mp(U[i], i));
}
A = _A;
B = _B;
if(M == N-1){ //TREE CASE
D = getDist();
findJeds(0, 0);
while(sz(jeds) > 1){
vpi njeds;
vpi ojeds;
for(int i = 0; i < sz(jeds)/2; i++){
njeds.pb(jeds[i]);
}
for(int i = sz(jeds)/2; i < sz(jeds); i++){
ojeds.pb(jeds[i]);
}
vi w(M, 0);
for(auto u: njeds){
w[u.f] = 1;
}
if(ask(w) == A*D){
jeds = ojeds;
}
else jeds = njeds;
}
answer(0, jeds[0].s);
return;
}
}
# | 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... |