Submission #1090125

# Submission time Handle Problem Language Result Execution time Memory
1090125 2024-09-17T18:30:20 Z LilPluton Race (IOI11_race) C++14
0 / 100
7 ms 14428 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

const int sz = 2e5 + 5;
int n, k;
vector<vector<pair<int, int>>> adj(sz);
map<int, int> a[sz];
long long sum[sz], dep[sz], res;

void comp(int u, int p, long long  c, int h) {
	a[u][c] = h;
	sum[u] = c;
	dep[u] = h;
	for (auto n : adj[u]) {
		if (p == n.first) { continue; }
		comp(n.first, u, c + n.second, h + 1);
	}
}

void dfs(int v, int p) {
    int t = k + 2 * sum[v];
    for (auto i : adj[v]) {
        if (i.first == p) {
            continue;
        }
        if (a[i.first].size() > a[v].size()) {
            swap(a[i.first], a[v]);
        }
        for (auto j : a[i.first]) {
            if (a[v].find(t - j.first) != a[v].end()) {
                res = min(res, a[v][t - j.first] + j.second - 2 * dep[v]);
            }
        }
        for (auto j : a[i.first]) {
            if (a[v].find(j.first) == a[v].end()) {
                a[v].insert(j);
            } else {
                a[v][j.first] = min(a[v][j.first], j.second);
            }
        }
    }
}

int best_path(int N, int K, int H[][2], int L[]) {
	if (k == 1) { return 0; }
	n = N;
	k = K;
	res = INT_MAX;
	for (int i = 0; i < n - 1; i++) {
		int u = H[i][0];
		int v = H[i][1];
		adj[u].push_back(pair<int,int> (v, L[i]));
		adj[v].push_back(pair<int,int> (u, L[i]));
	}
	comp(0, -1, 0, 0);
	dfs(0, -1);
	return res == INT_MAX ? -1 : res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -