제출 #36279

#제출 시각아이디문제언어결과실행 시간메모리
36279funcsr경주 (Race) (IOI11_race)C++14
21 / 100
3061 ms10108 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include "race.h"
using namespace std;
#define INF 1145141919
#define rep(i, n) for (int i=0; i<(n); i++)
#define _1 first
#define _2 second
#define all(x) x.begin(), x.end()
#define pb push_back
typedef pair<int, int> P;

int N, K;
int ans;
vector<P> G[200000];
void dfs(int x, int p, int r, int d) {
  if (d == K) ans = min(ans, r);
  for (P pp : G[x]) {
    int t = pp._1, nd = min(d+pp._2, INF);
    if (t == p) continue;
    dfs(t, x, r+1, nd);
  }
}

int best_path(int n, int k, int H[][2], int L[]) {
  N = n, K = k;
  rep(i, N) G[i].clear();
  rep(i, N-1) {
    G[H[i][0]].pb(P(H[i][1], L[i]));
    G[H[i][1]].pb(P(H[i][0], L[i]));
  }
  ans = INF;
  rep(i, N) dfs(i, -1, 0, 0);
  if (ans == INF) ans = -1;
  return ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...