답안 #986491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986491 2024-05-20T16:35:21 Z KasymK 경주 (Race) (IOI11_race) C++17
0 / 100
1 ms 2392 KB
#include "bits/stdc++.h"

#define MAX_N 500000

using namespace std;

const int Na = 1e3 + 5;

vector<pair<int, int>> adj[Na];

int mn = INT_MAX, Ka;

int dfs(int x, int pr, int jem, int edge){
	if(jem == Ka)
		return edge;
	if(jem > Ka)
		return Na;
	for(auto &i : adj[x])
		if(i.first != pr)
			mn = min(mn, dfs(i.first, x, jem + i.second, edge + 1));
	return mn;
}

int best_path(int n, int k, int H[][2], int L[]){
	Ka = k;
	for(int i = 0; i < n - 1; ++i)
		adj[H[i][0]].push_back({H[i][1], L[i]}), adj[H[i][1]].push_back({H[i][0], L[i]});
	int answer = INT_MAX;
	for(int i = 0; i < n; ++i)
		answer = min(answer, dfs(i, -1, 0, 0));
	return answer;
}

//static int N, K;
//static int H[MAX_N][2];
//static int L[MAX_N];
//static int solution;
//
//inline 
//void my_assert(int e) {if (!e) abort();}
//
//void read_input()
//{
//  int i;
//  my_assert(2==scanf("%d %d",&N,&K));
//  for(i=0; i<N-1; i++)
//    my_assert(3==scanf("%d %d %d",&H[i][0],&H[i][1],&L[i]));
//  my_assert(1==scanf("%d",&solution));
//}
//
//int main() {
//  int ans;
//  read_input();
//  ans = best_path(N,K,H,L);
//  if(ans==solution)
//    printf("Correct.\n");
//  else
//    printf("Incorrect. Returned %d, Expected %d.\n",ans,solution);
//
//  return 0;
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -