Submission #1369622

#TimeUsernameProblemLanguageResultExecution timeMemory
1369622nikakh경주 (Race) (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5;

vector<pair<int, int>> G[MAXN];
vector<long long> pre = {0};
int vis[MAXN], ans = MAXN;

void dfs(int u, long long D, int &K){
	vis[u] = 1;
	int find = lower_bound(pre.begin(), pre.end(), D - K) - pre.begin();
	if(find != (int)pre.size() && pre[find] == D - K){
		ans = min(ans, (int)pre.size() - find);
	}
	pre.push_back(D);
	for(auto &[v, L] : G[u]){
		if(vis[v]) continue;
		dfs(v, D + L, K);
	}
	pre.pop_back();
}

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], v = H[i][1], l = L[i];
		G[u].push_back({v, l});
		G[v].push_back({u, l});
	}
	dfs(0, 0, K);
	return ans == MAXN ? -1 : ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N = 3, K = 3;
	int H[N - 1][2] = {{0, 1}, {1, 2}}, L[N - 1] = {1, 1};
	cout << best_path(N, K, H, L) << '\n';
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccKMIDEg.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccYQzzlF.o:race.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status