# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
980410 |
2024-05-12T07:08:28 Z |
hieptk |
Race (IOI11_race) |
C++17 |
|
3 ms |
11100 KB |
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <map>
#include <sstream>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
const int nm = 200002;
vector<pair<int, ll>> adj[nm];
int H[nm][2], L[nm];
int Res;
unordered_map<ll, int> dfs(int i, int p, int k) {
unordered_map<ll, int> res;
for (auto [j, w]: adj[i]) {
if (j == p) continue;
auto resj = dfs(j, i, k);
for (auto [cost, len]: resj) {
if (cost + w > k) continue;
if (cost + w == k) {
Res = min(Res, len + 1);
} else if (res.count(k - cost - w)) {
Res = min(Res, res[k - cost - w] + len + 1);
}
if (res.count(cost + w) && len + 1 < res[cost + w]) res[cost + w] = len + 1;
else res[cost + w] = len + 1;
}
res[w] = 1;
}
// cout << "dfs " << i << "\n";
// for (auto [cost, len]: res) cout << cost << " " << len << "\n";
return res;
}
int best_path(int n, int k, int H[][2], int L[]) {
for (int i = 0; i < n - 1; ++i) {
adj[H[i][0]].emplace_back(H[i][1], L[i]);
adj[H[i][1]].emplace_back(H[i][0], L[i]);
}
Res = n + 1;
dfs(0, -1, k);
return Res <= n ? Res : -1;
}
// int main() {
// #ifdef LOCAL
// freopen("input.txt", "r", stdin);
// #endif
// ios::sync_with_stdio(0);
// cin.tie(0);
// int n, k;
// cin >> n >> k;
// for (int i = 0; i < n - 1; ++i) cin >> H[i][0] >> H[i][1] >> L[i];
// cout << best_path(n, k, H, L) << "\n";
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
11100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
11100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
11100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
11100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |