Submission #1024987

# Submission time Handle Problem Language Result Execution time Memory
1024987 2024-07-16T13:43:59 Z dosts Race (IOI11_race) C++17
100 / 100
287 ms 79184 KB
#include "race.h"
//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " << 
#define vi vector<int>
#define all(xx) xx.begin(),xx.end()
#define ps(xxx) cout << (xxx) << endl;
const int LIM = 2e5+1,inf = 1e18;
vector<pii> edges[LIM];

map<int,int> s[LIM];
int ans = inf;
int k;
void dfs(int node,int p,int d = 0,int dep = 0) {
  for (auto it : edges[node]) if (it.ss != p) dfs(it.ss,node,d+it.ff,dep+1);
  s[node][d] = dep;
  for (auto it : edges[node]) {
    if (it.ss == p) continue;
    if (s[it.ss].size() > s[node].size()) s[it.ss].swap(s[node]);
    for (auto it : s[it.ss]) {
      if (s[node].count(k+2*d-it.ff)) {
        ans = min(ans,it.ss+s[node][k+2*d-it.ff]-2*dep);
      }
    }

    for (auto it : s[it.ss]) {
      if (s[node].count(it.ff)) s[node][it.ff] = min(s[node][it.ff],it.ss);
      else s[node][it.ff] = it.ss;
      if (it.ff == k+d) {
        ans = min(ans,it.ss-dep);
      }
    }
    s[it.ss].clear();
  }
}


int32_t best_path(int32_t N, int32_t K, int32_t H[][2], int32_t L[])
{
  k = K;
  for (int i=0;i<N-1;i++) {
    edges[H[i][0]].push_back({L[i],H[i][1]});
    edges[H[i][1]].push_back({L[i],H[i][0]});
  }
  dfs(0,0);
  if (ans == inf) return -1;
  return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 5 ms 14428 KB Output is correct
5 Correct 6 ms 14556 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 5 ms 14468 KB Output is correct
9 Correct 7 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 5 ms 14340 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 5 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 5 ms 14428 KB Output is correct
5 Correct 6 ms 14556 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 5 ms 14468 KB Output is correct
9 Correct 7 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 5 ms 14340 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 5 ms 14428 KB Output is correct
19 Correct 5 ms 14456 KB Output is correct
20 Correct 5 ms 14424 KB Output is correct
21 Correct 6 ms 14428 KB Output is correct
22 Correct 8 ms 14428 KB Output is correct
23 Correct 6 ms 14684 KB Output is correct
24 Correct 7 ms 14428 KB Output is correct
25 Correct 6 ms 14680 KB Output is correct
26 Correct 6 ms 14428 KB Output is correct
27 Correct 7 ms 14552 KB Output is correct
28 Correct 6 ms 14428 KB Output is correct
29 Correct 7 ms 14428 KB Output is correct
30 Correct 6 ms 14684 KB Output is correct
31 Correct 6 ms 14444 KB Output is correct
32 Correct 5 ms 14428 KB Output is correct
33 Correct 6 ms 14684 KB Output is correct
34 Correct 7 ms 14684 KB Output is correct
35 Correct 7 ms 14684 KB Output is correct
36 Correct 6 ms 14684 KB Output is correct
37 Correct 7 ms 14684 KB Output is correct
38 Correct 9 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 5 ms 14428 KB Output is correct
5 Correct 6 ms 14556 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 5 ms 14468 KB Output is correct
9 Correct 7 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 5 ms 14340 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 5 ms 14428 KB Output is correct
19 Correct 68 ms 20908 KB Output is correct
20 Correct 79 ms 20816 KB Output is correct
21 Correct 68 ms 20868 KB Output is correct
22 Correct 78 ms 20792 KB Output is correct
23 Correct 101 ms 21260 KB Output is correct
24 Correct 71 ms 20568 KB Output is correct
25 Correct 78 ms 31828 KB Output is correct
26 Correct 44 ms 40536 KB Output is correct
27 Correct 124 ms 33876 KB Output is correct
28 Correct 181 ms 79184 KB Output is correct
29 Correct 201 ms 77140 KB Output is correct
30 Correct 123 ms 33888 KB Output is correct
31 Correct 123 ms 33876 KB Output is correct
32 Correct 151 ms 34052 KB Output is correct
33 Correct 155 ms 27620 KB Output is correct
34 Correct 235 ms 39760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14424 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 5 ms 14428 KB Output is correct
5 Correct 6 ms 14556 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14428 KB Output is correct
8 Correct 5 ms 14468 KB Output is correct
9 Correct 7 ms 14428 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 6 ms 14428 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 5 ms 14340 KB Output is correct
17 Correct 6 ms 14428 KB Output is correct
18 Correct 5 ms 14428 KB Output is correct
19 Correct 5 ms 14456 KB Output is correct
20 Correct 5 ms 14424 KB Output is correct
21 Correct 6 ms 14428 KB Output is correct
22 Correct 8 ms 14428 KB Output is correct
23 Correct 6 ms 14684 KB Output is correct
24 Correct 7 ms 14428 KB Output is correct
25 Correct 6 ms 14680 KB Output is correct
26 Correct 6 ms 14428 KB Output is correct
27 Correct 7 ms 14552 KB Output is correct
28 Correct 6 ms 14428 KB Output is correct
29 Correct 7 ms 14428 KB Output is correct
30 Correct 6 ms 14684 KB Output is correct
31 Correct 6 ms 14444 KB Output is correct
32 Correct 5 ms 14428 KB Output is correct
33 Correct 6 ms 14684 KB Output is correct
34 Correct 7 ms 14684 KB Output is correct
35 Correct 7 ms 14684 KB Output is correct
36 Correct 6 ms 14684 KB Output is correct
37 Correct 7 ms 14684 KB Output is correct
38 Correct 9 ms 14684 KB Output is correct
39 Correct 68 ms 20908 KB Output is correct
40 Correct 79 ms 20816 KB Output is correct
41 Correct 68 ms 20868 KB Output is correct
42 Correct 78 ms 20792 KB Output is correct
43 Correct 101 ms 21260 KB Output is correct
44 Correct 71 ms 20568 KB Output is correct
45 Correct 78 ms 31828 KB Output is correct
46 Correct 44 ms 40536 KB Output is correct
47 Correct 124 ms 33876 KB Output is correct
48 Correct 181 ms 79184 KB Output is correct
49 Correct 201 ms 77140 KB Output is correct
50 Correct 123 ms 33888 KB Output is correct
51 Correct 123 ms 33876 KB Output is correct
52 Correct 151 ms 34052 KB Output is correct
53 Correct 155 ms 27620 KB Output is correct
54 Correct 235 ms 39760 KB Output is correct
55 Correct 15 ms 15656 KB Output is correct
56 Correct 10 ms 15192 KB Output is correct
57 Correct 38 ms 21188 KB Output is correct
58 Correct 40 ms 26572 KB Output is correct
59 Correct 68 ms 46836 KB Output is correct
60 Correct 184 ms 77948 KB Output is correct
61 Correct 157 ms 35792 KB Output is correct
62 Correct 127 ms 34020 KB Output is correct
63 Correct 139 ms 34128 KB Output is correct
64 Correct 287 ms 35668 KB Output is correct
65 Correct 276 ms 40272 KB Output is correct
66 Correct 220 ms 72328 KB Output is correct
67 Correct 112 ms 38580 KB Output is correct
68 Correct 222 ms 38992 KB Output is correct
69 Correct 246 ms 42480 KB Output is correct
70 Correct 222 ms 38044 KB Output is correct