Submission #221498

# Submission time Handle Problem Language Result Execution time Memory
221498 2020-04-10T10:33:57 Z a_player Race (IOI11_race) C++14
100 / 100
537 ms 37744 KB
    #include "race.h"
    #include <bits/stdc++.h>
    #define f first
    #define s second
      
    using namespace std;
      
    const int nax=2e5+5;
    const int vax=1e6+5;
    typedef long long ll;
      
    vector<pair<int,int>  > grafo[nax];
    int ans=INT_MAX;
    int N,K;
    int ss,cc;
    pair<int,int> m[vax];
    vector<pair<int,int> > vv;
    bitset<nax> vis;
    int in;
    void incl(int n, int a, int d, int v){
        if(K<v)return;
        if(a!=-1){
          if(v==K)ans=min(ans,d);
        if(m[K-v].s==in)ans=min(ans,m[K-v].f+d);
        vv.push_back({v,d});
        }
        for(auto x:grafo[n]){
          if(!vis[x.f]&&x.f!=a){
          incl(x.f,n,d+1,v+x.s);
          }
          if(a==-1){
            while(!vv.empty()){
                auto p=vv.back();
                vv.pop_back();
                if(m[p.f].s==in)m[p.f].f=min(m[p.f].f,p.s);
                else m[p.f]={p.s,in};
            }
          }
        }
    }
    int findc(int n, int a, int num){
      int s=0;
      int mas=0;
          for(auto x:grafo[n]){
            if(x.f!=a&&!vis[x.f]){
              int p=findc(x.f,n,num);
              s+=p;
              mas=max(mas,p);
            }
          }
          if(mas<=num/2&&s>=num/2)cc=n;
          return s+1;
    }
    int findsize(int n, int a){
      int s=0;
      for(auto x:grafo[n]){
        if(!vis[x.f]&&x.f!=a){
          s+=findsize(x.f,n);
        }
      }
      return s+1;
    }
    void centroid(int n){
      in=n;
      incl(n,-1,0,0);
      vis[n]=1;
      for(auto x:grafo[n]){
        if(vis[x.f])continue;
        ss=findsize(x.f,-1);
        findc(x.f,-1,ss);
        centroid(cc);
      }
      
    }
      
    int best_path(int N, int K, int H[][2], int L[]){
      ::N=N,::K=K;
      for(int i=0;i<N-1;i++){
        grafo[H[i][0]].push_back({H[i][1],L[i]});
        grafo[H[i][1]].push_back({H[i][0],L[i]});
      }
      for(int i=0;i<vax;i++)m[i]={-1,-1};
      findc(0,-1,N);
      centroid(cc);
      if(ans==INT_MAX)return -1;
      return ans;
    }
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12800 KB Output is correct
2 Correct 12 ms 12800 KB Output is correct
3 Correct 12 ms 12800 KB Output is correct
4 Correct 12 ms 12800 KB Output is correct
5 Correct 12 ms 12800 KB Output is correct
6 Correct 12 ms 12928 KB Output is correct
7 Correct 12 ms 12800 KB Output is correct
8 Correct 12 ms 12800 KB Output is correct
9 Correct 12 ms 12800 KB Output is correct
10 Correct 12 ms 12800 KB Output is correct
11 Correct 12 ms 12800 KB Output is correct
12 Correct 12 ms 12800 KB Output is correct
13 Correct 12 ms 12800 KB Output is correct
14 Correct 12 ms 12800 KB Output is correct
15 Correct 12 ms 12800 KB Output is correct
16 Correct 12 ms 12800 KB Output is correct
17 Correct 12 ms 12800 KB Output is correct
18 Correct 12 ms 12800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12800 KB Output is correct
2 Correct 12 ms 12800 KB Output is correct
3 Correct 12 ms 12800 KB Output is correct
4 Correct 12 ms 12800 KB Output is correct
5 Correct 12 ms 12800 KB Output is correct
6 Correct 12 ms 12928 KB Output is correct
7 Correct 12 ms 12800 KB Output is correct
8 Correct 12 ms 12800 KB Output is correct
9 Correct 12 ms 12800 KB Output is correct
10 Correct 12 ms 12800 KB Output is correct
11 Correct 12 ms 12800 KB Output is correct
12 Correct 12 ms 12800 KB Output is correct
13 Correct 12 ms 12800 KB Output is correct
14 Correct 12 ms 12800 KB Output is correct
15 Correct 12 ms 12800 KB Output is correct
16 Correct 12 ms 12800 KB Output is correct
17 Correct 12 ms 12800 KB Output is correct
18 Correct 12 ms 12800 KB Output is correct
19 Correct 12 ms 12928 KB Output is correct
20 Correct 12 ms 12800 KB Output is correct
21 Correct 13 ms 12928 KB Output is correct
22 Correct 13 ms 12928 KB Output is correct
23 Correct 13 ms 12928 KB Output is correct
24 Correct 14 ms 12928 KB Output is correct
25 Correct 14 ms 12928 KB Output is correct
26 Correct 13 ms 12928 KB Output is correct
27 Correct 13 ms 12928 KB Output is correct
28 Correct 13 ms 12928 KB Output is correct
29 Correct 13 ms 12928 KB Output is correct
30 Correct 13 ms 12928 KB Output is correct
31 Correct 13 ms 12928 KB Output is correct
32 Correct 13 ms 12928 KB Output is correct
33 Correct 14 ms 12928 KB Output is correct
34 Correct 13 ms 12928 KB Output is correct
35 Correct 13 ms 12928 KB Output is correct
36 Correct 13 ms 12928 KB Output is correct
37 Correct 13 ms 12928 KB Output is correct
38 Correct 13 ms 12928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12800 KB Output is correct
2 Correct 12 ms 12800 KB Output is correct
3 Correct 12 ms 12800 KB Output is correct
4 Correct 12 ms 12800 KB Output is correct
5 Correct 12 ms 12800 KB Output is correct
6 Correct 12 ms 12928 KB Output is correct
7 Correct 12 ms 12800 KB Output is correct
8 Correct 12 ms 12800 KB Output is correct
9 Correct 12 ms 12800 KB Output is correct
10 Correct 12 ms 12800 KB Output is correct
11 Correct 12 ms 12800 KB Output is correct
12 Correct 12 ms 12800 KB Output is correct
13 Correct 12 ms 12800 KB Output is correct
14 Correct 12 ms 12800 KB Output is correct
15 Correct 12 ms 12800 KB Output is correct
16 Correct 12 ms 12800 KB Output is correct
17 Correct 12 ms 12800 KB Output is correct
18 Correct 12 ms 12800 KB Output is correct
19 Correct 160 ms 17788 KB Output is correct
20 Correct 164 ms 18168 KB Output is correct
21 Correct 159 ms 18424 KB Output is correct
22 Correct 151 ms 18424 KB Output is correct
23 Correct 104 ms 18168 KB Output is correct
24 Correct 88 ms 18168 KB Output is correct
25 Correct 146 ms 21624 KB Output is correct
26 Correct 119 ms 25848 KB Output is correct
27 Correct 211 ms 23032 KB Output is correct
28 Correct 330 ms 37368 KB Output is correct
29 Correct 325 ms 36216 KB Output is correct
30 Correct 220 ms 23160 KB Output is correct
31 Correct 209 ms 23032 KB Output is correct
32 Correct 249 ms 23032 KB Output is correct
33 Correct 273 ms 22008 KB Output is correct
34 Correct 241 ms 22008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12800 KB Output is correct
2 Correct 12 ms 12800 KB Output is correct
3 Correct 12 ms 12800 KB Output is correct
4 Correct 12 ms 12800 KB Output is correct
5 Correct 12 ms 12800 KB Output is correct
6 Correct 12 ms 12928 KB Output is correct
7 Correct 12 ms 12800 KB Output is correct
8 Correct 12 ms 12800 KB Output is correct
9 Correct 12 ms 12800 KB Output is correct
10 Correct 12 ms 12800 KB Output is correct
11 Correct 12 ms 12800 KB Output is correct
12 Correct 12 ms 12800 KB Output is correct
13 Correct 12 ms 12800 KB Output is correct
14 Correct 12 ms 12800 KB Output is correct
15 Correct 12 ms 12800 KB Output is correct
16 Correct 12 ms 12800 KB Output is correct
17 Correct 12 ms 12800 KB Output is correct
18 Correct 12 ms 12800 KB Output is correct
19 Correct 12 ms 12928 KB Output is correct
20 Correct 12 ms 12800 KB Output is correct
21 Correct 13 ms 12928 KB Output is correct
22 Correct 13 ms 12928 KB Output is correct
23 Correct 13 ms 12928 KB Output is correct
24 Correct 14 ms 12928 KB Output is correct
25 Correct 14 ms 12928 KB Output is correct
26 Correct 13 ms 12928 KB Output is correct
27 Correct 13 ms 12928 KB Output is correct
28 Correct 13 ms 12928 KB Output is correct
29 Correct 13 ms 12928 KB Output is correct
30 Correct 13 ms 12928 KB Output is correct
31 Correct 13 ms 12928 KB Output is correct
32 Correct 13 ms 12928 KB Output is correct
33 Correct 14 ms 12928 KB Output is correct
34 Correct 13 ms 12928 KB Output is correct
35 Correct 13 ms 12928 KB Output is correct
36 Correct 13 ms 12928 KB Output is correct
37 Correct 13 ms 12928 KB Output is correct
38 Correct 13 ms 12928 KB Output is correct
39 Correct 160 ms 17788 KB Output is correct
40 Correct 164 ms 18168 KB Output is correct
41 Correct 159 ms 18424 KB Output is correct
42 Correct 151 ms 18424 KB Output is correct
43 Correct 104 ms 18168 KB Output is correct
44 Correct 88 ms 18168 KB Output is correct
45 Correct 146 ms 21624 KB Output is correct
46 Correct 119 ms 25848 KB Output is correct
47 Correct 211 ms 23032 KB Output is correct
48 Correct 330 ms 37368 KB Output is correct
49 Correct 325 ms 36216 KB Output is correct
50 Correct 220 ms 23160 KB Output is correct
51 Correct 209 ms 23032 KB Output is correct
52 Correct 249 ms 23032 KB Output is correct
53 Correct 273 ms 22008 KB Output is correct
54 Correct 241 ms 22008 KB Output is correct
55 Correct 25 ms 13568 KB Output is correct
56 Correct 22 ms 13568 KB Output is correct
57 Correct 104 ms 18808 KB Output is correct
58 Correct 53 ms 18156 KB Output is correct
59 Correct 123 ms 25848 KB Output is correct
60 Correct 464 ms 37744 KB Output is correct
61 Correct 233 ms 23160 KB Output is correct
62 Correct 239 ms 23032 KB Output is correct
63 Correct 303 ms 23164 KB Output is correct
64 Correct 537 ms 27120 KB Output is correct
65 Correct 315 ms 26892 KB Output is correct
66 Correct 447 ms 36720 KB Output is correct
67 Correct 138 ms 26472 KB Output is correct
68 Correct 310 ms 26620 KB Output is correct
69 Correct 308 ms 26744 KB Output is correct
70 Correct 326 ms 26104 KB Output is correct