제출 #792304

#제출 시각아이디문제언어결과실행 시간메모리
792304limabeans경주 (Race) (IOI11_race)C++17
21 / 100
3061 ms12524 KiB
#include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>


using namespace std;
using ll = long long;
const int maxn=2e5+10;


vector<pair<ll,int>> g[maxn];

pair<ll,int> dfs(int at, int p, int dst) {
  if (at==dst) {
    return {0,0};
  }
  for (auto ed: g[at]) {
    int to = ed.second;
    if (to==p) continue;
    auto cur = dfs(to, at, dst);
    if (cur.second != -1) {
      cur.first += ed.first;
      cur.second++;
      return cur;
    }
  }
  return {0,-1};
}

int best_path(int n, int k, int H[][2], int L[]) {
  for (int i=0; i<n-1; i++) {
    int u=H[i][0];
    int v=H[i][1];
    int w=L[i];
    g[v].push_back({w,u});
    g[u].push_back({w,v});
  }

  int best=n;
  for (int i=0; i<n; i++) {
    for (int j=i+1; j<n; j++) {
      pair<ll,int> cur = dfs(i,i,j);
      if (cur.first == k) {
	best = min(best, cur.second);
      }
    }
  }
  return (best == n ? -1 : best);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...