답안 #691314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
691314 2023-01-31T05:05:13 Z zeroesandones 경주 (Race) (IOI11_race) C++17
21 / 100
22 ms 2900 KB
#include "bits/stdc++.h"
#include "race.h"
using namespace std;

using ll = long long;
using vi = vector<ll>;
using pi = pair<long long, long long>;

#define pb emplace_back
#define fr first
#define sc second

const int mxN = 1005;
const ll inf = 1e15;

vector<pi> adj[mxN];
pi dep[mxN];

void dfs(int x, int p, int d, int l) {
  dep[x].fr = d;
  dep[x].sc = l;
  for(auto [i, w] : adj[x]) {
    if(i != p) {
      dfs(i, x, d + 1, l + w);
    }
  }
}

int best_path(int N, int K, int H[][2], int L[])
{
  for(int i = 0; i < N - 1; ++i) {
    adj[H[i][0]].pb(H[i][1], L[i]);
    adj[H[i][1]].pb(H[i][0], L[i]);
  }

  ll ans = inf;
  for(int i = 0; i < N; ++i) {
    pi id = {0, 0};
    fill(dep, dep + mxN, id);
    dfs(i, -1, 0, 0);
    for(int j = 0; j < N; ++j) {
      if(dep[j].sc == K)
        ans = min(ans, dep[j].fr);
    }
  }

  return (ans == inf ? -1 : ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 15 ms 416 KB Output is correct
22 Correct 17 ms 340 KB Output is correct
23 Correct 15 ms 420 KB Output is correct
24 Correct 14 ms 416 KB Output is correct
25 Correct 14 ms 420 KB Output is correct
26 Correct 14 ms 420 KB Output is correct
27 Correct 14 ms 416 KB Output is correct
28 Correct 14 ms 412 KB Output is correct
29 Correct 14 ms 340 KB Output is correct
30 Correct 15 ms 340 KB Output is correct
31 Correct 14 ms 340 KB Output is correct
32 Correct 15 ms 416 KB Output is correct
33 Correct 17 ms 340 KB Output is correct
34 Correct 10 ms 340 KB Output is correct
35 Correct 11 ms 428 KB Output is correct
36 Correct 8 ms 340 KB Output is correct
37 Correct 8 ms 340 KB Output is correct
38 Correct 10 ms 412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Runtime error 22 ms 2900 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 15 ms 416 KB Output is correct
22 Correct 17 ms 340 KB Output is correct
23 Correct 15 ms 420 KB Output is correct
24 Correct 14 ms 416 KB Output is correct
25 Correct 14 ms 420 KB Output is correct
26 Correct 14 ms 420 KB Output is correct
27 Correct 14 ms 416 KB Output is correct
28 Correct 14 ms 412 KB Output is correct
29 Correct 14 ms 340 KB Output is correct
30 Correct 15 ms 340 KB Output is correct
31 Correct 14 ms 340 KB Output is correct
32 Correct 15 ms 416 KB Output is correct
33 Correct 17 ms 340 KB Output is correct
34 Correct 10 ms 340 KB Output is correct
35 Correct 11 ms 428 KB Output is correct
36 Correct 8 ms 340 KB Output is correct
37 Correct 8 ms 340 KB Output is correct
38 Correct 10 ms 412 KB Output is correct
39 Runtime error 22 ms 2900 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -