Submission #348727

#TimeUsernameProblemLanguageResultExecution timeMemory
348727idk321Race (IOI11_race)C++11
9 / 100
184 ms50696 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200001; const int K = 101; vector<array<int, 2>> adj[N]; int dp[N][K]; int n, k; void dfs1(int node, int parent) { dp[node][0] = 0; for (auto next : adj[node]) { if (next[0] == parent) continue; dfs1(next[0], node); for (int i = 0; i + next[1] <= k; i++) { //cout << node << " " << next[0] << " " << i << " " << dp[next[0]][i] << endl; dp[node][i + next[1]] = min(dp[node][i + next[1]], dp[next[0]][i] + 1); } } } int best_path(int n1, int k1, int H[][2], int L[]) { n = n1; k = k1; for (int i = 0; i < n; i++) for (int j = 0; j <= k; j++) dp[i][j] = N; for (int i = 0; i < n; i++) { adj[H[i][0]].push_back({H[i][1], L[i]}); adj[H[i][1]].push_back({H[i][0], L[i]}); } dfs1(0, -1); int res = N; for (int i = 0; i < n; i++) { res = min(res, dp[i][k]); //for (int j = 0; j <= k; j++) cout << "oj " << i << " " << dp[i][k] << endl; } if (res == N) return -1; return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...