Submission #685221

# Submission time Handle Problem Language Result Execution time Memory
685221 2023-01-23T17:17:43 Z cadmiumsky Race (IOI11_race) C++14
100 / 100
459 ms 70732 KB
#include <bits/stdc++.h>
#include "race.h"

using namespace std;

using ll = long long;
#define int ll 

#define sz(x) (x).size()


using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 2e5 + 5, vmax = 1e6 + 5, inf = 1e9 + 5;

struct MN {
  int x, atr;
  MN(int a = inf, int b = -1): x(a), atr(b) {;}
  MN operator += (const MN& a) {
    //if(a.atr == atr)
    #warning idk
      x = min(x, a.x);
    return *this;
  } 
};
struct MN2 {
  MN a, b;
  MN2(MN x = MN(), MN y = MN()): a(x), b(y) {;}
  MN2 operator += (const MN& x) {
    if(x.x < a.x) {
      if(x.atr == a.atr)
        a.x = x.x;
      else {
        b = a;
        a = x;
      }
    }
    else if(x.x < b.x && x.atr != a.atr) {
      b = x;
    }
    return *this;
  }
  int operator()(const MN& x) const {
    return x.x + (x.atr == a.atr? b.x : a.x);
  }
};


vector<pii> g[nmax];

int K;

int mn = nmax;

namespace Centr {
  MN2 freq[vmax];
  vector<tii> lst;
  
  int area[nmax];
  int occ[nmax];
  
  void init(int node, int f) {
    area[node] = 0;
    if(occ[node] == 1) return;
    for(auto [x, e] : g[node]) {
      if(x != f)
        init(x, node),
        area[node] += area[x];
    }
    area[node]++;
    return;
  }
  
  int findcentr(int node, int f, int thresh) {
    
    for(auto [x, e] : g[node]) {
      if(x == f) continue;
      if(occ[x] == 0 && area[x] > thresh) {
        return findcentr(x, node, thresh);
      }
    } 
    return node;
    
  }
  
  void dfs(int node, int f, int atr, int dist, int h = 1) {
    if(dist > K) return;
    if(occ[node] == 1) return;
    lst.emplace_back(dist, h, atr);
    //cerr << node << ' ' << ' ' << f << ' ' << atr << ' ' << dist << ' ' << h << '\n';
    for(auto [x, e] : g[node]) {
      if(x == f) continue;
      dfs(x, node, atr, dist + e, h + 1);
    }
  }
  
  void decomp(int node) {
    init(node, node);
    //cerr << area[node] << ' ';
    node = findcentr(node, node, area[node] / 2);
    //cerr<< area[node] << ' ' << node << '\n';
    
    lst.clear();
    lst.emplace_back(0, 0, node);
    for(auto [x, e] : g[node]) {
      dfs(x, node, x, e);
    }
    //cerr << node << ":\n";
    for(auto [ptr, val, atr] : lst) {
      //cerr << ptr << ' ' << val << ' ' << atr << '\n';
      freq[ptr] += MN(val, atr);
    }
      
    for(auto [ptr, val, atr] : lst) {
      mn = min(mn, freq[K - ptr](MN(val, atr)));
    }
    
    for(auto [ptr, var, atr] : lst) {
      freq[ptr] = MN2();
    }
    
    occ[node] = 1;
    //cerr << "-------\n";
    for(auto [x, e] : g[node]) {
      if(occ[x] != 1)
        decomp(x);
    }
    return;
  }
  
}


signed best_path(signed n, signed k, signed H[][2], signed L[]) {
  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]);
  Centr::lst.reserve(n);
  Centr::decomp(0);
  if(mn == nmax) return -1;
  return mn;
}

Compilation message

race.cpp:22:6: warning: #warning idk [-Wcpp]
   22 |     #warning idk
      |      ^~~~~~~
race.cpp: In function 'void Centr::init(ll, ll)':
race.cpp:66:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |     for(auto [x, e] : g[node]) {
      |              ^
race.cpp: In function 'll Centr::findcentr(ll, ll, ll)':
race.cpp:77:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   77 |     for(auto [x, e] : g[node]) {
      |              ^
race.cpp: In function 'void Centr::dfs(ll, ll, ll, ll, ll)':
race.cpp:92:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   92 |     for(auto [x, e] : g[node]) {
      |              ^
race.cpp: In function 'void Centr::decomp(ll)':
race.cpp:106:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  106 |     for(auto [x, e] : g[node]) {
      |              ^
race.cpp:110:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  110 |     for(auto [ptr, val, atr] : lst) {
      |              ^
race.cpp:115:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  115 |     for(auto [ptr, val, atr] : lst) {
      |              ^
race.cpp:119:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  119 |     for(auto [ptr, var, atr] : lst) {
      |              ^
race.cpp:125:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  125 |     for(auto [x, e] : g[node]) {
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 16 ms 36436 KB Output is correct
2 Correct 16 ms 36312 KB Output is correct
3 Correct 15 ms 36308 KB Output is correct
4 Correct 18 ms 36264 KB Output is correct
5 Correct 15 ms 36308 KB Output is correct
6 Correct 15 ms 36312 KB Output is correct
7 Correct 15 ms 36308 KB Output is correct
8 Correct 19 ms 36256 KB Output is correct
9 Correct 16 ms 36316 KB Output is correct
10 Correct 16 ms 36328 KB Output is correct
11 Correct 15 ms 36312 KB Output is correct
12 Correct 18 ms 36308 KB Output is correct
13 Correct 17 ms 36308 KB Output is correct
14 Correct 16 ms 36308 KB Output is correct
15 Correct 17 ms 36296 KB Output is correct
16 Correct 15 ms 36320 KB Output is correct
17 Correct 16 ms 36308 KB Output is correct
18 Correct 16 ms 36320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 36436 KB Output is correct
2 Correct 16 ms 36312 KB Output is correct
3 Correct 15 ms 36308 KB Output is correct
4 Correct 18 ms 36264 KB Output is correct
5 Correct 15 ms 36308 KB Output is correct
6 Correct 15 ms 36312 KB Output is correct
7 Correct 15 ms 36308 KB Output is correct
8 Correct 19 ms 36256 KB Output is correct
9 Correct 16 ms 36316 KB Output is correct
10 Correct 16 ms 36328 KB Output is correct
11 Correct 15 ms 36312 KB Output is correct
12 Correct 18 ms 36308 KB Output is correct
13 Correct 17 ms 36308 KB Output is correct
14 Correct 16 ms 36308 KB Output is correct
15 Correct 17 ms 36296 KB Output is correct
16 Correct 15 ms 36320 KB Output is correct
17 Correct 16 ms 36308 KB Output is correct
18 Correct 16 ms 36320 KB Output is correct
19 Correct 21 ms 36300 KB Output is correct
20 Correct 16 ms 36308 KB Output is correct
21 Correct 16 ms 36420 KB Output is correct
22 Correct 19 ms 36412 KB Output is correct
23 Correct 19 ms 36352 KB Output is correct
24 Correct 17 ms 36436 KB Output is correct
25 Correct 17 ms 36436 KB Output is correct
26 Correct 18 ms 36436 KB Output is correct
27 Correct 17 ms 36320 KB Output is correct
28 Correct 17 ms 36468 KB Output is correct
29 Correct 17 ms 36456 KB Output is correct
30 Correct 18 ms 36436 KB Output is correct
31 Correct 17 ms 36396 KB Output is correct
32 Correct 20 ms 36320 KB Output is correct
33 Correct 17 ms 36460 KB Output is correct
34 Correct 16 ms 36436 KB Output is correct
35 Correct 19 ms 36324 KB Output is correct
36 Correct 16 ms 36320 KB Output is correct
37 Correct 20 ms 36428 KB Output is correct
38 Correct 17 ms 36400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 36436 KB Output is correct
2 Correct 16 ms 36312 KB Output is correct
3 Correct 15 ms 36308 KB Output is correct
4 Correct 18 ms 36264 KB Output is correct
5 Correct 15 ms 36308 KB Output is correct
6 Correct 15 ms 36312 KB Output is correct
7 Correct 15 ms 36308 KB Output is correct
8 Correct 19 ms 36256 KB Output is correct
9 Correct 16 ms 36316 KB Output is correct
10 Correct 16 ms 36328 KB Output is correct
11 Correct 15 ms 36312 KB Output is correct
12 Correct 18 ms 36308 KB Output is correct
13 Correct 17 ms 36308 KB Output is correct
14 Correct 16 ms 36308 KB Output is correct
15 Correct 17 ms 36296 KB Output is correct
16 Correct 15 ms 36320 KB Output is correct
17 Correct 16 ms 36308 KB Output is correct
18 Correct 16 ms 36320 KB Output is correct
19 Correct 120 ms 45784 KB Output is correct
20 Correct 141 ms 45740 KB Output is correct
21 Correct 138 ms 46244 KB Output is correct
22 Correct 118 ms 47468 KB Output is correct
23 Correct 84 ms 45932 KB Output is correct
24 Correct 64 ms 45132 KB Output is correct
25 Correct 128 ms 48460 KB Output is correct
26 Correct 93 ms 53720 KB Output is correct
27 Correct 215 ms 55472 KB Output is correct
28 Correct 296 ms 66744 KB Output is correct
29 Correct 286 ms 65744 KB Output is correct
30 Correct 170 ms 55580 KB Output is correct
31 Correct 173 ms 55508 KB Output is correct
32 Correct 210 ms 55564 KB Output is correct
33 Correct 225 ms 54264 KB Output is correct
34 Correct 210 ms 54988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 36436 KB Output is correct
2 Correct 16 ms 36312 KB Output is correct
3 Correct 15 ms 36308 KB Output is correct
4 Correct 18 ms 36264 KB Output is correct
5 Correct 15 ms 36308 KB Output is correct
6 Correct 15 ms 36312 KB Output is correct
7 Correct 15 ms 36308 KB Output is correct
8 Correct 19 ms 36256 KB Output is correct
9 Correct 16 ms 36316 KB Output is correct
10 Correct 16 ms 36328 KB Output is correct
11 Correct 15 ms 36312 KB Output is correct
12 Correct 18 ms 36308 KB Output is correct
13 Correct 17 ms 36308 KB Output is correct
14 Correct 16 ms 36308 KB Output is correct
15 Correct 17 ms 36296 KB Output is correct
16 Correct 15 ms 36320 KB Output is correct
17 Correct 16 ms 36308 KB Output is correct
18 Correct 16 ms 36320 KB Output is correct
19 Correct 21 ms 36300 KB Output is correct
20 Correct 16 ms 36308 KB Output is correct
21 Correct 16 ms 36420 KB Output is correct
22 Correct 19 ms 36412 KB Output is correct
23 Correct 19 ms 36352 KB Output is correct
24 Correct 17 ms 36436 KB Output is correct
25 Correct 17 ms 36436 KB Output is correct
26 Correct 18 ms 36436 KB Output is correct
27 Correct 17 ms 36320 KB Output is correct
28 Correct 17 ms 36468 KB Output is correct
29 Correct 17 ms 36456 KB Output is correct
30 Correct 18 ms 36436 KB Output is correct
31 Correct 17 ms 36396 KB Output is correct
32 Correct 20 ms 36320 KB Output is correct
33 Correct 17 ms 36460 KB Output is correct
34 Correct 16 ms 36436 KB Output is correct
35 Correct 19 ms 36324 KB Output is correct
36 Correct 16 ms 36320 KB Output is correct
37 Correct 20 ms 36428 KB Output is correct
38 Correct 17 ms 36400 KB Output is correct
39 Correct 120 ms 45784 KB Output is correct
40 Correct 141 ms 45740 KB Output is correct
41 Correct 138 ms 46244 KB Output is correct
42 Correct 118 ms 47468 KB Output is correct
43 Correct 84 ms 45932 KB Output is correct
44 Correct 64 ms 45132 KB Output is correct
45 Correct 128 ms 48460 KB Output is correct
46 Correct 93 ms 53720 KB Output is correct
47 Correct 215 ms 55472 KB Output is correct
48 Correct 296 ms 66744 KB Output is correct
49 Correct 286 ms 65744 KB Output is correct
50 Correct 170 ms 55580 KB Output is correct
51 Correct 173 ms 55508 KB Output is correct
52 Correct 210 ms 55564 KB Output is correct
53 Correct 225 ms 54264 KB Output is correct
54 Correct 210 ms 54988 KB Output is correct
55 Correct 22 ms 37264 KB Output is correct
56 Correct 24 ms 37444 KB Output is correct
57 Correct 84 ms 48264 KB Output is correct
58 Correct 48 ms 47056 KB Output is correct
59 Correct 101 ms 53724 KB Output is correct
60 Correct 459 ms 70732 KB Output is correct
61 Correct 180 ms 56476 KB Output is correct
62 Correct 187 ms 60164 KB Output is correct
63 Correct 254 ms 60068 KB Output is correct
64 Correct 452 ms 60168 KB Output is correct
65 Correct 236 ms 55940 KB Output is correct
66 Correct 394 ms 63928 KB Output is correct
67 Correct 145 ms 59188 KB Output is correct
68 Correct 236 ms 57676 KB Output is correct
69 Correct 239 ms 57652 KB Output is correct
70 Correct 230 ms 56700 KB Output is correct