Submission #722730

# Submission time Handle Problem Language Result Execution time Memory
722730 2023-04-12T18:29:52 Z ktkerem Race (IOI11_race) C++17
100 / 100
2571 ms 89936 KB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
#include "race.h"
typedef long long ll;
typedef long double ld;
typedef __int128 vll;
typedef long long ftyp;
typedef std::complex<ftyp> vec;
#define llll std::pair<ll , ll>
#define pb push_back
#define fi first
#define sec second
#define cx real
#define cy imag
#define all(a) a.begin() , a.end()
#define debug std::cout << "!!ALERT ALERT!!" << std::endl;  
const ll limit = 1e12+7;
const ll sus = 2e5+5;
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
std::vector<llll> adj[sus];
ll ddc = 0 , dd[sus] , vis[sus] , sub[sus] , ff;
std::map<ll , ll> mp[sus];
ll calsub(ll crt , ll prv){
  //std::cout << crt << " " << prv << std::endl;
  sub[crt] = 1; 
  vis[crt] = 1;
  for(auto j:adj[crt]){
    if(j.fi != prv && vis[j.fi] == 0){
      sub[crt]+=calsub(j.fi , crt);
    }
  }
  return sub[crt];
}
ll fndcent(ll crt , ll prv , ll prt){
  //std::cout << crt << " " << prv << " " << prt << std::endl;
  ll kd = (prt > ff?0:1);
  ll p = -1;
  for(auto j:adj[crt]){
    if(j.fi != prv && dd[j.fi] == 0){
      ll i = fndcent(j.fi , crt  , sub[crt] - sub[j.fi] + prt);
      if(p == -1){
        p = i;
      }
      if(sub[j.fi] > ff){
        kd =0;
      }
    }
  }
  if(kd){
    return crt;
  }
  return p;
}
void ctf(ll crt , ll prv , ll fpr , ll o , ll p){
  //std::cout << crt << " " << prv << " " << fpr << std::endl;
  if(mp[p][fpr] == 0){
    mp[p][fpr] = o;
  }
  mp[p][fpr] = std::min(mp[p][fpr] , o);
  for(auto j:adj[crt]){
    if(j.fi != prv && dd[j.fi] == 0){
      ctf(j.fi , crt , fpr + j.sec , o+1 , p);
    }
  }
}
ll calans(ll crt ,ll k){
  ddc++;
  //std::cout << crt << " " << k << std::endl;
  dd[crt] = 1;
  ll jj = 0;
  ll x = 0;
  for(auto j:adj[crt]){
    if(dd[j.fi]==0){
      mp[x].clear();
      x++;
    }
  }
  for(auto j:adj[crt]){
    if(dd[j.fi]==0){
      ctf(j.fi , crt , j.sec , 1 , jj++);      
    }
  }
  ll ns = limit;
  std::map<ll , ll> mpx;
  mpx[0] = 0;
  for(ll i = 0;x>i;i++){
    for(auto j:mp[i]){
      if(mpx[k-j.fi] != 0 || k - j.fi == 0){
        ns = std::min(mpx[k-j.fi] + j.sec , ns);
      }
    }
    for(auto j:mp[i]){
      if(j.fi == 0){
        //do nothing
      }
      else if(mpx[j.fi] == 0){
        mpx[j.fi] = j.sec;
      }
      else{
        mpx[j.fi] = std::min(j.sec , mpx[j.fi]);
      } 
    }
  }
  return ns;
}
int best_path(int n , int k , int h[][2] ,int cst[]){
  for(ll i = 0 ; n-1>i;i++){
    //std::cout << h[i][0] << " " << h[i][1] << " " << cst[i] << std::endl; 
    adj[h[i][0]].pb({h[i][1] , cst[i]});
    adj[h[i][1]].pb({h[i][0] , cst[i]});
  }
  ll ans = limit;
  ddc = 0;
  for(ll i = 0 ; n>=i;i++){
    dd[i] = 0;
  }
  while(n > ddc){
    for(ll i = 0;n>i;i++){
      if(vis[i] == 0){
        calsub(i , -1);
        ff = sub[i]/2;
        ll cento = fndcent(i , -1 , 0);
        ans = std::min(calans(cento , k) , ans);
      }
    } 
    for(ll i = 0;n>i;i++){
      vis[i] = dd[i];
      sub[i] = 0;
    }
  }
  if(ans == limit){
    return -1;
  }
  return ans;
}
/*void solve(){
  ll n , k;std::cin >> n >> k;
  std::cout << n << " " << k << std::endl;
  ll alcst[n+5] , hkn[n+5][2];
  for(ll i = 0;n-1>i;i++){
    for(ll j = 0;2>j;j++){
      std::cin >> hkn[i][j];
    }
    std::cin >> alcst[i];
  }
  ll ots = best_path(n , k , hkn , alcst);
  std::cout << ots << "\n";
  return;
}
int main(){
  std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("in.txt" , "r" , stdin);
    freopen("out.txt" , "w" , stdout);
  #endif
  ll t = 1;
  //std::cin >> t;
  while(t--){
    solve();
  }
}*/

Compilation message

race.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14392 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 9 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 9 ms 14420 KB Output is correct
8 Correct 9 ms 14460 KB Output is correct
9 Correct 10 ms 14420 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14364 KB Output is correct
12 Correct 10 ms 14408 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14448 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 8 ms 14452 KB Output is correct
18 Correct 9 ms 14356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14392 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 9 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 9 ms 14420 KB Output is correct
8 Correct 9 ms 14460 KB Output is correct
9 Correct 10 ms 14420 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14364 KB Output is correct
12 Correct 10 ms 14408 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14448 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 8 ms 14452 KB Output is correct
18 Correct 9 ms 14356 KB Output is correct
19 Correct 8 ms 14424 KB Output is correct
20 Correct 9 ms 14444 KB Output is correct
21 Correct 11 ms 14496 KB Output is correct
22 Correct 14 ms 14680 KB Output is correct
23 Correct 12 ms 14688 KB Output is correct
24 Correct 11 ms 14676 KB Output is correct
25 Correct 11 ms 14676 KB Output is correct
26 Correct 10 ms 14676 KB Output is correct
27 Correct 9 ms 14424 KB Output is correct
28 Correct 11 ms 14676 KB Output is correct
29 Correct 13 ms 14676 KB Output is correct
30 Correct 11 ms 14684 KB Output is correct
31 Correct 12 ms 14680 KB Output is correct
32 Correct 11 ms 14676 KB Output is correct
33 Correct 11 ms 14720 KB Output is correct
34 Correct 10 ms 14676 KB Output is correct
35 Correct 10 ms 14676 KB Output is correct
36 Correct 11 ms 14684 KB Output is correct
37 Correct 11 ms 14676 KB Output is correct
38 Correct 10 ms 14680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14392 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 9 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 9 ms 14420 KB Output is correct
8 Correct 9 ms 14460 KB Output is correct
9 Correct 10 ms 14420 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14364 KB Output is correct
12 Correct 10 ms 14408 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14448 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 8 ms 14452 KB Output is correct
18 Correct 9 ms 14356 KB Output is correct
19 Correct 442 ms 24460 KB Output is correct
20 Correct 400 ms 24504 KB Output is correct
21 Correct 441 ms 24480 KB Output is correct
22 Correct 418 ms 24564 KB Output is correct
23 Correct 568 ms 25120 KB Output is correct
24 Correct 262 ms 24140 KB Output is correct
25 Correct 349 ms 30724 KB Output is correct
26 Correct 126 ms 33388 KB Output is correct
27 Correct 564 ms 42048 KB Output is correct
28 Correct 2430 ms 89936 KB Output is correct
29 Correct 2386 ms 88584 KB Output is correct
30 Correct 528 ms 42060 KB Output is correct
31 Correct 535 ms 41936 KB Output is correct
32 Correct 733 ms 42064 KB Output is correct
33 Correct 1193 ms 34552 KB Output is correct
34 Correct 2246 ms 72052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 8 ms 14392 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 9 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 9 ms 14420 KB Output is correct
8 Correct 9 ms 14460 KB Output is correct
9 Correct 10 ms 14420 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14364 KB Output is correct
12 Correct 10 ms 14408 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14448 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 8 ms 14452 KB Output is correct
18 Correct 9 ms 14356 KB Output is correct
19 Correct 8 ms 14424 KB Output is correct
20 Correct 9 ms 14444 KB Output is correct
21 Correct 11 ms 14496 KB Output is correct
22 Correct 14 ms 14680 KB Output is correct
23 Correct 12 ms 14688 KB Output is correct
24 Correct 11 ms 14676 KB Output is correct
25 Correct 11 ms 14676 KB Output is correct
26 Correct 10 ms 14676 KB Output is correct
27 Correct 9 ms 14424 KB Output is correct
28 Correct 11 ms 14676 KB Output is correct
29 Correct 13 ms 14676 KB Output is correct
30 Correct 11 ms 14684 KB Output is correct
31 Correct 12 ms 14680 KB Output is correct
32 Correct 11 ms 14676 KB Output is correct
33 Correct 11 ms 14720 KB Output is correct
34 Correct 10 ms 14676 KB Output is correct
35 Correct 10 ms 14676 KB Output is correct
36 Correct 11 ms 14684 KB Output is correct
37 Correct 11 ms 14676 KB Output is correct
38 Correct 10 ms 14680 KB Output is correct
39 Correct 442 ms 24460 KB Output is correct
40 Correct 400 ms 24504 KB Output is correct
41 Correct 441 ms 24480 KB Output is correct
42 Correct 418 ms 24564 KB Output is correct
43 Correct 568 ms 25120 KB Output is correct
44 Correct 262 ms 24140 KB Output is correct
45 Correct 349 ms 30724 KB Output is correct
46 Correct 126 ms 33388 KB Output is correct
47 Correct 564 ms 42048 KB Output is correct
48 Correct 2430 ms 89936 KB Output is correct
49 Correct 2386 ms 88584 KB Output is correct
50 Correct 528 ms 42060 KB Output is correct
51 Correct 535 ms 41936 KB Output is correct
52 Correct 733 ms 42064 KB Output is correct
53 Correct 1193 ms 34552 KB Output is correct
54 Correct 2246 ms 72052 KB Output is correct
55 Correct 47 ms 16472 KB Output is correct
56 Correct 31 ms 15420 KB Output is correct
57 Correct 190 ms 24764 KB Output is correct
58 Correct 66 ms 30028 KB Output is correct
59 Correct 798 ms 48512 KB Output is correct
60 Correct 2450 ms 85896 KB Output is correct
61 Correct 604 ms 46852 KB Output is correct
62 Correct 584 ms 42088 KB Output is correct
63 Correct 771 ms 41996 KB Output is correct
64 Correct 2234 ms 56060 KB Output is correct
65 Correct 1921 ms 72720 KB Output is correct
66 Correct 2571 ms 85688 KB Output is correct
67 Correct 194 ms 46912 KB Output is correct
68 Correct 962 ms 67872 KB Output is correct
69 Correct 959 ms 68084 KB Output is correct
70 Correct 856 ms 65452 KB Output is correct