# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1112037 |
2024-11-13T14:41:00 Z |
FucKanh |
Race (IOI11_race) |
C++14 |
|
0 ms |
0 KB |
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pii pair<int,int>
#include "race.h"
using namespace std;
const int maxn = 2e5 + 2;
int f[(int)1e6 + 2];
int sz[maxn],h[maxn],k;
vector<pii> a[maxn];
int ans = LLONG_MAX;
map<int,int> mp[maxn];
//void pre(int u, int pa = -1) {
// sz[u] = 1;
// for (int i =0 ;i < a[u].size(); i++) {
// int v = a[u][i].first;
// if (v == pa) continue;
// h[v] = h[u] + 1;
// pre(v,u);
// sz[u] += sz[v];
// if (sz[a[u][0].first] <= sz[v]) {
// swap(a[u][0], a[u][i]);
// }
// }
//}
//
//void add(int u, int w, int root, int pa) {
// if (w < k && f[k-w]) {
// ans = min(ans, f[k-w] + h[u] - h[root]);
// }
// else if (w==k) {
// ans = min(ans, h[u] - h[root]);
// }
// f[w] = (f[w] == 0 ? h[u] : min(h[u], f[w]));
// for (int i =0 ;i < a[u].size(); i++) {
// int v = a[u][i].first;
// if (v == pa) continue;
// add(v,w+a[u][i].second,root,u);
// }
//}
//
//void del(int u, int w, int pa) {
// f[w] = 0;
// for (int i =0 ;i < a[u].size(); i++) {
// int v = a[u][i].first;
// if (v == pa) continue;
// del(v,w+a[u][i].second,u);
// }
//}
//
//void dfs(int u, int pa = 1) {
//// cerr << ": " << u << endl;
// for (int i = 1; i < a[u].size(); i++) {
// int v = a[u][i].first;
// if (v==pa) continue;
//// cerr << u << "->" << v <<endl;
// dfs(v,u);
// del(v,a[u][i].second,u);
// }
// if (a[u][0].first == pa) return;
//
//
// dfs(a[u][0].first,u);
// for (int i = 1; i < a[u].size(); i++) {
// int v = a[u][i].first;
// if (v==pa) continue;
// add(v,a[u][i].second,u,u);
// }
//
// int w = a[u][0].second;
// if (w < k && f[k-w]) {
// ans = min(ans, f[k-w] + 1);
// }
// else if (w==k) {
// ans = min(ans, 1ll);
// }
// f[w] = (f[w] == 0 ? h[u] + 1 : min(h[u] + 1, f[w]));
//}
void dfs(int u, int w, int pa) {
for (pii tmp : a[u]) {
int wv,v; tie(v,wv) = tmp;
if (v==pa) continue;
h[v] = h[u] + 1;
dfs(v,w+wv,u);
int t = mp[v][w+wv];
mp[v][w+wv] = (t == 0) ? h[v] : min(t,h[v]);
if (mp[u].size() < mp[v].size()) swap(mp[u],mp[v]);
for (pii val : mp[v]) {
if (val.second==0) continue;
if (val.first - w < k && mp[u][k-val.first+w] != 0) {
ans = min(ans, mp[u][k-val.first+w] - h[u] + val.second - h[u]);
}
}
mp[u].insert(mp[v].begin(),mp[v].end());
if (mp[u][w + k] != 0) {
ans = min(ans, mp[u][w+k]-h[u]);
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K;
for (int i = 0; i < N - 1; i++){
int x = H[i][0], y= H[i][1];
int w = L[i];
a[x].push_back({y,w});
a[y].push_back({x,w});
}
h[0] = 1;
dfs(0,0,-1);
return ans == LLONG_MAX ? -1 : ans;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
//// int N=11,K=12;
//// int H[10][2] = { {0,1}, {0,2}, {2,3}, {3,4}, {4,5}, {0,6}, {6,7}, {6,8}, {8,9}, {8,10} };
//// int L[11] = {3,4,5,4,6,3,2,5,6,7};
//
// int N=3,K=3 ;
// int H[2][2] = { {0,1}, {1,2} };
// int L[2] = {1,1};
// cout << best_path(N,K,H,L) << endl;
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccG60cQD.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccfqI6TB.o:grader.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccfqI6TB.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status