답안 #24194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24194 2017-06-01T12:10:05 Z Nirjhor 경주 (Race) (IOI11_race) C++14
100 / 100
887 ms 76284 KB
#include <bits/stdc++.h>
#include "race.h"

using namespace std;

typedef long long ll;
typedef pair <int, ll> edge;

#define x first
#define y second

const int N = 200010;
const int INF = 1e9 + 10;

vector <edge> g[N];
int n, k, ans = INF;

void dfs (int u, int from, map <ll, int> &f, ll &key_f, int &val_f) {
  f[0] = 0;
  key_f = val_f = 0;
  for (edge e : g[u]) {
    int v = e.x; 
    ll w = e.y;
    if (v == from) continue;
    map <ll, int> t;
    ll key_t; 
    int val_t;
    dfs(v, u, t, key_t, val_t);
    key_t += w, ++val_t;
    if (t.size() > f.size()) {
      f.swap(t);
      swap(key_f, key_t);
      swap(val_f, val_t);
    }
    for (auto it : t) {
      ll more = k - it.x - key_t - key_f;
      if (f.find(more) != f.end()) {
        ans = min(ans, it.y + f[more] + val_t + val_f);
      }
    }
    key_t -= key_f, val_t -= val_f;
    for (auto it : t) {
      if (f.find(it.x + key_t) == f.end()) f[it.x + key_t] = INF;
      f[it.x + key_t] = min(f[it.x + key_t], it.y + val_t);
    }
  }
  // cout << u << " ----> \n";
  // for (auto it : f) {
  //   cout << it.x << " " << it.y << endl;
  // }
}

int best_path (int N, int K, int H[][2], int L[]) {
  n = N, k = K;
  for (int i = 0; i < n - 1; ++i) {
    g[H[i][0]].emplace_back(H[i][1], L[i]);
    g[H[i][1]].emplace_back(H[i][0], L[i]);
  }
  map <ll, int> f;
  ll key;
  int val;
  dfs(0, 0, f, key, val);
  if (ans >= INF / 2) ans = -1;
  return ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5116 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 7 ms 5224 KB Output is correct
4 Correct 8 ms 5224 KB Output is correct
5 Correct 7 ms 5224 KB Output is correct
6 Correct 7 ms 5224 KB Output is correct
7 Correct 6 ms 5224 KB Output is correct
8 Correct 8 ms 5224 KB Output is correct
9 Correct 5 ms 5228 KB Output is correct
10 Correct 6 ms 5228 KB Output is correct
11 Correct 6 ms 5228 KB Output is correct
12 Correct 6 ms 5228 KB Output is correct
13 Correct 5 ms 5228 KB Output is correct
14 Correct 6 ms 5228 KB Output is correct
15 Correct 6 ms 5292 KB Output is correct
16 Correct 6 ms 5292 KB Output is correct
17 Correct 6 ms 5292 KB Output is correct
18 Correct 6 ms 5292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5116 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 7 ms 5224 KB Output is correct
4 Correct 8 ms 5224 KB Output is correct
5 Correct 7 ms 5224 KB Output is correct
6 Correct 7 ms 5224 KB Output is correct
7 Correct 6 ms 5224 KB Output is correct
8 Correct 8 ms 5224 KB Output is correct
9 Correct 5 ms 5228 KB Output is correct
10 Correct 6 ms 5228 KB Output is correct
11 Correct 6 ms 5228 KB Output is correct
12 Correct 6 ms 5228 KB Output is correct
13 Correct 5 ms 5228 KB Output is correct
14 Correct 6 ms 5228 KB Output is correct
15 Correct 6 ms 5292 KB Output is correct
16 Correct 6 ms 5292 KB Output is correct
17 Correct 6 ms 5292 KB Output is correct
18 Correct 6 ms 5292 KB Output is correct
19 Correct 5 ms 5292 KB Output is correct
20 Correct 6 ms 5292 KB Output is correct
21 Correct 7 ms 5348 KB Output is correct
22 Correct 10 ms 5348 KB Output is correct
23 Correct 7 ms 5348 KB Output is correct
24 Correct 7 ms 5348 KB Output is correct
25 Correct 7 ms 5360 KB Output is correct
26 Correct 8 ms 5384 KB Output is correct
27 Correct 6 ms 5384 KB Output is correct
28 Correct 7 ms 5456 KB Output is correct
29 Correct 8 ms 5456 KB Output is correct
30 Correct 8 ms 5456 KB Output is correct
31 Correct 8 ms 5456 KB Output is correct
32 Correct 8 ms 5456 KB Output is correct
33 Correct 10 ms 5456 KB Output is correct
34 Correct 9 ms 5456 KB Output is correct
35 Correct 11 ms 5456 KB Output is correct
36 Correct 8 ms 5536 KB Output is correct
37 Correct 8 ms 5536 KB Output is correct
38 Correct 8 ms 5536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5116 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 7 ms 5224 KB Output is correct
4 Correct 8 ms 5224 KB Output is correct
5 Correct 7 ms 5224 KB Output is correct
6 Correct 7 ms 5224 KB Output is correct
7 Correct 6 ms 5224 KB Output is correct
8 Correct 8 ms 5224 KB Output is correct
9 Correct 5 ms 5228 KB Output is correct
10 Correct 6 ms 5228 KB Output is correct
11 Correct 6 ms 5228 KB Output is correct
12 Correct 6 ms 5228 KB Output is correct
13 Correct 5 ms 5228 KB Output is correct
14 Correct 6 ms 5228 KB Output is correct
15 Correct 6 ms 5292 KB Output is correct
16 Correct 6 ms 5292 KB Output is correct
17 Correct 6 ms 5292 KB Output is correct
18 Correct 6 ms 5292 KB Output is correct
19 Correct 155 ms 11708 KB Output is correct
20 Correct 148 ms 11820 KB Output is correct
21 Correct 146 ms 11820 KB Output is correct
22 Correct 150 ms 11820 KB Output is correct
23 Correct 242 ms 12340 KB Output is correct
24 Correct 162 ms 12340 KB Output is correct
25 Correct 123 ms 27132 KB Output is correct
26 Correct 84 ms 40828 KB Output is correct
27 Correct 297 ms 40828 KB Output is correct
28 Correct 530 ms 76284 KB Output is correct
29 Correct 553 ms 76284 KB Output is correct
30 Correct 284 ms 76284 KB Output is correct
31 Correct 282 ms 76284 KB Output is correct
32 Correct 332 ms 76284 KB Output is correct
33 Correct 277 ms 76284 KB Output is correct
34 Correct 556 ms 76284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5116 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 7 ms 5224 KB Output is correct
4 Correct 8 ms 5224 KB Output is correct
5 Correct 7 ms 5224 KB Output is correct
6 Correct 7 ms 5224 KB Output is correct
7 Correct 6 ms 5224 KB Output is correct
8 Correct 8 ms 5224 KB Output is correct
9 Correct 5 ms 5228 KB Output is correct
10 Correct 6 ms 5228 KB Output is correct
11 Correct 6 ms 5228 KB Output is correct
12 Correct 6 ms 5228 KB Output is correct
13 Correct 5 ms 5228 KB Output is correct
14 Correct 6 ms 5228 KB Output is correct
15 Correct 6 ms 5292 KB Output is correct
16 Correct 6 ms 5292 KB Output is correct
17 Correct 6 ms 5292 KB Output is correct
18 Correct 6 ms 5292 KB Output is correct
19 Correct 5 ms 5292 KB Output is correct
20 Correct 6 ms 5292 KB Output is correct
21 Correct 7 ms 5348 KB Output is correct
22 Correct 10 ms 5348 KB Output is correct
23 Correct 7 ms 5348 KB Output is correct
24 Correct 7 ms 5348 KB Output is correct
25 Correct 7 ms 5360 KB Output is correct
26 Correct 8 ms 5384 KB Output is correct
27 Correct 6 ms 5384 KB Output is correct
28 Correct 7 ms 5456 KB Output is correct
29 Correct 8 ms 5456 KB Output is correct
30 Correct 8 ms 5456 KB Output is correct
31 Correct 8 ms 5456 KB Output is correct
32 Correct 8 ms 5456 KB Output is correct
33 Correct 10 ms 5456 KB Output is correct
34 Correct 9 ms 5456 KB Output is correct
35 Correct 11 ms 5456 KB Output is correct
36 Correct 8 ms 5536 KB Output is correct
37 Correct 8 ms 5536 KB Output is correct
38 Correct 8 ms 5536 KB Output is correct
39 Correct 155 ms 11708 KB Output is correct
40 Correct 148 ms 11820 KB Output is correct
41 Correct 146 ms 11820 KB Output is correct
42 Correct 150 ms 11820 KB Output is correct
43 Correct 242 ms 12340 KB Output is correct
44 Correct 162 ms 12340 KB Output is correct
45 Correct 123 ms 27132 KB Output is correct
46 Correct 84 ms 40828 KB Output is correct
47 Correct 297 ms 40828 KB Output is correct
48 Correct 530 ms 76284 KB Output is correct
49 Correct 553 ms 76284 KB Output is correct
50 Correct 284 ms 76284 KB Output is correct
51 Correct 282 ms 76284 KB Output is correct
52 Correct 332 ms 76284 KB Output is correct
53 Correct 277 ms 76284 KB Output is correct
54 Correct 556 ms 76284 KB Output is correct
55 Correct 24 ms 76284 KB Output is correct
56 Correct 14 ms 76284 KB Output is correct
57 Correct 87 ms 76284 KB Output is correct
58 Correct 72 ms 76284 KB Output is correct
59 Correct 189 ms 76284 KB Output is correct
60 Correct 579 ms 76284 KB Output is correct
61 Correct 366 ms 76284 KB Output is correct
62 Correct 302 ms 76284 KB Output is correct
63 Correct 316 ms 76284 KB Output is correct
64 Correct 887 ms 76284 KB Output is correct
65 Correct 872 ms 76284 KB Output is correct
66 Correct 555 ms 76284 KB Output is correct
67 Correct 193 ms 76284 KB Output is correct
68 Correct 596 ms 76284 KB Output is correct
69 Correct 577 ms 76284 KB Output is correct
70 Correct 566 ms 76284 KB Output is correct