답안 #115115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115115 2019-06-05T10:48:04 Z oolimry 경주 (Race) (IOI11_race) C++14
43 / 100
3000 ms 262144 KB
#include "race.h"
#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> ii;

static vector<ii> adj[200005];
static bool vis[200005];
unordered_map<int,int> dp[200005];
int k;
int ans = 102345678;
void dfs(int u){
  vis[u] = true;
  for(int i = 0;i < adj[u].size();i++){
    int v = adj[u][i].first;
    int w = adj[u][i].second;

    if(vis[v]) continue;
    dfs(v);
    vector<ii> updates;
    //if(dp[v].size() > dp[u].size()) swap(dp[u],dp[v]);
    for(ii x : dp[v]){
      int value = w + x.first;
      if(value <= k){
        if(dp[u].find(k-value) != dp[u].end()){
          ans = min(ans, dp[u][k-value] + x.second + 1);
        }
        updates.push_back({value,x.second+1});
      }
    }
    dp[v].clear();

    for(ii x : updates){
      if(dp[u].find(x.first) == dp[u].end()){
        dp[u][x.first] = x.second;
      }
      else{
        dp[u][x.first] = min(x.second,dp[u][x.first]);
      }
    }
  }
}
int best_path(int N, int K, int H[][2], int L[])
{
  k = K;
  int n = N;
  for(int i = 0;i < n;i++) dp[i][0] = 0;
  for(int i = 0;i < n-1;i++){
    int a = H[i][0];
    int b = H[i][1];
    int c = L[i];
    adj[a].push_back({b,c});
    adj[b].push_back({a,c});
  }

  dfs(0);
  if(ans > n) return -1;
  return ans;
}

Compilation message

race.cpp: In function 'void dfs(int)':
race.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i < adj[u].size();i++){
                 ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16128 KB Output is correct
2 Correct 16 ms 16128 KB Output is correct
3 Correct 15 ms 16000 KB Output is correct
4 Correct 15 ms 16000 KB Output is correct
5 Correct 15 ms 16000 KB Output is correct
6 Correct 16 ms 16000 KB Output is correct
7 Correct 16 ms 16000 KB Output is correct
8 Correct 15 ms 16000 KB Output is correct
9 Correct 16 ms 16000 KB Output is correct
10 Correct 16 ms 16128 KB Output is correct
11 Correct 16 ms 16000 KB Output is correct
12 Correct 16 ms 15984 KB Output is correct
13 Correct 17 ms 16000 KB Output is correct
14 Correct 18 ms 16000 KB Output is correct
15 Correct 16 ms 16000 KB Output is correct
16 Correct 16 ms 16128 KB Output is correct
17 Correct 16 ms 16000 KB Output is correct
18 Correct 15 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16128 KB Output is correct
2 Correct 16 ms 16128 KB Output is correct
3 Correct 15 ms 16000 KB Output is correct
4 Correct 15 ms 16000 KB Output is correct
5 Correct 15 ms 16000 KB Output is correct
6 Correct 16 ms 16000 KB Output is correct
7 Correct 16 ms 16000 KB Output is correct
8 Correct 15 ms 16000 KB Output is correct
9 Correct 16 ms 16000 KB Output is correct
10 Correct 16 ms 16128 KB Output is correct
11 Correct 16 ms 16000 KB Output is correct
12 Correct 16 ms 15984 KB Output is correct
13 Correct 17 ms 16000 KB Output is correct
14 Correct 18 ms 16000 KB Output is correct
15 Correct 16 ms 16000 KB Output is correct
16 Correct 16 ms 16128 KB Output is correct
17 Correct 16 ms 16000 KB Output is correct
18 Correct 15 ms 16000 KB Output is correct
19 Correct 14 ms 16000 KB Output is correct
20 Correct 15 ms 15936 KB Output is correct
21 Correct 16 ms 16128 KB Output is correct
22 Correct 16 ms 16128 KB Output is correct
23 Correct 17 ms 16128 KB Output is correct
24 Correct 16 ms 16128 KB Output is correct
25 Correct 17 ms 16256 KB Output is correct
26 Correct 17 ms 16128 KB Output is correct
27 Correct 15 ms 16128 KB Output is correct
28 Correct 18 ms 16128 KB Output is correct
29 Correct 17 ms 16256 KB Output is correct
30 Correct 19 ms 16256 KB Output is correct
31 Correct 18 ms 16256 KB Output is correct
32 Correct 18 ms 16256 KB Output is correct
33 Correct 20 ms 16384 KB Output is correct
34 Correct 20 ms 16384 KB Output is correct
35 Correct 20 ms 16512 KB Output is correct
36 Correct 21 ms 16524 KB Output is correct
37 Correct 30 ms 17144 KB Output is correct
38 Correct 26 ms 16888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16128 KB Output is correct
2 Correct 16 ms 16128 KB Output is correct
3 Correct 15 ms 16000 KB Output is correct
4 Correct 15 ms 16000 KB Output is correct
5 Correct 15 ms 16000 KB Output is correct
6 Correct 16 ms 16000 KB Output is correct
7 Correct 16 ms 16000 KB Output is correct
8 Correct 15 ms 16000 KB Output is correct
9 Correct 16 ms 16000 KB Output is correct
10 Correct 16 ms 16128 KB Output is correct
11 Correct 16 ms 16000 KB Output is correct
12 Correct 16 ms 15984 KB Output is correct
13 Correct 17 ms 16000 KB Output is correct
14 Correct 18 ms 16000 KB Output is correct
15 Correct 16 ms 16000 KB Output is correct
16 Correct 16 ms 16128 KB Output is correct
17 Correct 16 ms 16000 KB Output is correct
18 Correct 15 ms 16000 KB Output is correct
19 Correct 261 ms 33496 KB Output is correct
20 Correct 263 ms 33404 KB Output is correct
21 Correct 239 ms 32248 KB Output is correct
22 Correct 232 ms 30600 KB Output is correct
23 Correct 203 ms 28468 KB Output is correct
24 Correct 166 ms 29688 KB Output is correct
25 Correct 1641 ms 160012 KB Output is correct
26 Correct 1122 ms 133444 KB Output is correct
27 Correct 505 ms 54080 KB Output is correct
28 Correct 398 ms 65784 KB Output is correct
29 Correct 393 ms 63952 KB Output is correct
30 Correct 535 ms 54224 KB Output is correct
31 Correct 531 ms 54264 KB Output is correct
32 Correct 569 ms 48844 KB Output is correct
33 Correct 2801 ms 246896 KB Output is correct
34 Correct 309 ms 37752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16128 KB Output is correct
2 Correct 16 ms 16128 KB Output is correct
3 Correct 15 ms 16000 KB Output is correct
4 Correct 15 ms 16000 KB Output is correct
5 Correct 15 ms 16000 KB Output is correct
6 Correct 16 ms 16000 KB Output is correct
7 Correct 16 ms 16000 KB Output is correct
8 Correct 15 ms 16000 KB Output is correct
9 Correct 16 ms 16000 KB Output is correct
10 Correct 16 ms 16128 KB Output is correct
11 Correct 16 ms 16000 KB Output is correct
12 Correct 16 ms 15984 KB Output is correct
13 Correct 17 ms 16000 KB Output is correct
14 Correct 18 ms 16000 KB Output is correct
15 Correct 16 ms 16000 KB Output is correct
16 Correct 16 ms 16128 KB Output is correct
17 Correct 16 ms 16000 KB Output is correct
18 Correct 15 ms 16000 KB Output is correct
19 Correct 14 ms 16000 KB Output is correct
20 Correct 15 ms 15936 KB Output is correct
21 Correct 16 ms 16128 KB Output is correct
22 Correct 16 ms 16128 KB Output is correct
23 Correct 17 ms 16128 KB Output is correct
24 Correct 16 ms 16128 KB Output is correct
25 Correct 17 ms 16256 KB Output is correct
26 Correct 17 ms 16128 KB Output is correct
27 Correct 15 ms 16128 KB Output is correct
28 Correct 18 ms 16128 KB Output is correct
29 Correct 17 ms 16256 KB Output is correct
30 Correct 19 ms 16256 KB Output is correct
31 Correct 18 ms 16256 KB Output is correct
32 Correct 18 ms 16256 KB Output is correct
33 Correct 20 ms 16384 KB Output is correct
34 Correct 20 ms 16384 KB Output is correct
35 Correct 20 ms 16512 KB Output is correct
36 Correct 21 ms 16524 KB Output is correct
37 Correct 30 ms 17144 KB Output is correct
38 Correct 26 ms 16888 KB Output is correct
39 Correct 261 ms 33496 KB Output is correct
40 Correct 263 ms 33404 KB Output is correct
41 Correct 239 ms 32248 KB Output is correct
42 Correct 232 ms 30600 KB Output is correct
43 Correct 203 ms 28468 KB Output is correct
44 Correct 166 ms 29688 KB Output is correct
45 Correct 1641 ms 160012 KB Output is correct
46 Correct 1122 ms 133444 KB Output is correct
47 Correct 505 ms 54080 KB Output is correct
48 Correct 398 ms 65784 KB Output is correct
49 Correct 393 ms 63952 KB Output is correct
50 Correct 535 ms 54224 KB Output is correct
51 Correct 531 ms 54264 KB Output is correct
52 Correct 569 ms 48844 KB Output is correct
53 Correct 2801 ms 246896 KB Output is correct
54 Correct 309 ms 37752 KB Output is correct
55 Correct 39 ms 18044 KB Output is correct
56 Correct 32 ms 17528 KB Output is correct
57 Correct 128 ms 28880 KB Output is correct
58 Correct 75 ms 27760 KB Output is correct
59 Execution timed out 3087 ms 262144 KB Time limit exceeded
60 Halted 0 ms 0 KB -