Submission #71632

# Submission time Handle Problem Language Result Execution time Memory
71632 2018-08-25T09:19:18 Z MANcity Race (IOI11_race) C++14
43 / 100
3000 ms 36564 KB
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
#include "race.h"
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
const LL Mod=1000*1000*1000+7;
int K;
vector<vector<pair<int,int> > > G(200002);
int sizeVer[200002];
int used[200002];
int sumSize;
int verNum;
int ka[5000002];
int ANSWER=1000000;
void dfs(int v,int p)
{
    if(G[v].size()==1 && G[v][0].first==p)
        sizeVer[v]=1;
    else
        sizeVer[v]=0;
    for0(j,G[v].size()-1)
    {
        int to=G[v][j].first;
        if(to!=p && used[to]==0)
        {
            dfs(to,v);
            sizeVer[v]+=sizeVer[to];
        }
    }
    verNum++;
    sizeVer[v]+=1;
    sumSize+=sizeVer[v];
}
int find_centr(int v,int p)
{
    int u=0;
    for0(j,G[v].size()-1)
    {
        int to=G[v][j].first;
        if(to!=p && used[to]==0)
        {
            if(2*sizeVer[to]>verNum)
            {
                u=1;
                return find_centr(to,v);
            }
        }
    }
    if(u==0)
        return v;
}
int update_dfs(int v,int p,int len,int qan)
{
    if(ka[len]==-1)
        ka[len]=qan;
    else
        ka[len]=min(qan,ka[len]);
    if(K>=len)
    for0(j,G[v].size()-1)
    {
        int to=G[v][j].first;
        int l=G[v][j].second;
        if(to!=p && used[to]==0)
        {
            update_dfs(to,v,len+l,qan+1);
        }
    }
}
int stug_dfs(int v,int p,int len,int qan)
{
    if(K>=len)
    {
        //cout<<v<<" AAAA "<<len<<" "<<K-len<<" "<<ka[K-len]<<endl;
        if(ka[K-len]!=-1)
        {
            ANSWER=min(ANSWER,ka[K-len]+qan);
            //cout<<v<<" "<<len<<" "<<ANSWER<<endl;
        }
    }
    if(K>=len)
    for0(j,G[v].size()-1)
    {
        int to=G[v][j].first;
        int l=G[v][j].second;
        if(to!=p && used[to]==0)
        {
            stug_dfs(to,v,len+l,qan+1);
        }
    }
}
void solve(int v)
{
    for0(i,K)
        ka[i]=-1;
    ka[0]=0;
    sumSize=0;
    verNum=0;
    dfs(v,-1);
    if(verNum==1)
        return;
    int centr=find_centr(v,-1);
    //cout<<v<<" "<<centr<<endl;
    for0(i,G[centr].size()-1)
    {
        int to=G[centr][i].first;
        int len=G[centr][i].second;
        if(used[to]==0)
        {
            stug_dfs(to,centr,len,1);
            update_dfs(to,centr,len,1);
        }
    }
    used[centr]=1;
    for0(i,G[centr].size()-1)
    {
        int to=G[centr][i].first;
        if(used[to]==0)
        {
            solve(to);
        }
    }
}
int best_path(int N, int K_0, int H[][2], int L[])
{
    K=K_0;
    for0(i,N-2)
    {
        G[H[i][0]].pb({H[i][1],L[i]});
        G[H[i][1]].pb({H[i][0],L[i]});
    }
    solve(1);
    if(ANSWER==1000000)
        return -1;
    return ANSWER;
}
/*
11 12
0 1 3
0 2 4
2 3 5
3 4 4
4 5 6
0 6 3
6 7 2
6 8 5
8 9 6
8 10 7
2
*/
/*
6 16
0 1 10
0 2 1
2 3 2
3 4 3
2 5 4
4
*/

Compilation message

race.cpp: In function 'int update_dfs(int, int, int, int)':
race.cpp:85:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
race.cpp: In function 'int stug_dfs(int, int, int, int)':
race.cpp:107:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
race.cpp: In function 'int find_centr(int, int)':
race.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
2 Correct 9 ms 5220 KB Output is correct
3 Correct 7 ms 5220 KB Output is correct
4 Correct 7 ms 5220 KB Output is correct
5 Correct 6 ms 5228 KB Output is correct
6 Correct 6 ms 5304 KB Output is correct
7 Correct 7 ms 5308 KB Output is correct
8 Correct 6 ms 5308 KB Output is correct
9 Correct 6 ms 5308 KB Output is correct
10 Correct 7 ms 5344 KB Output is correct
11 Correct 8 ms 5348 KB Output is correct
12 Correct 7 ms 5348 KB Output is correct
13 Correct 8 ms 5356 KB Output is correct
14 Correct 10 ms 5388 KB Output is correct
15 Correct 7 ms 5388 KB Output is correct
16 Correct 7 ms 5396 KB Output is correct
17 Correct 6 ms 5396 KB Output is correct
18 Correct 8 ms 5396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
2 Correct 9 ms 5220 KB Output is correct
3 Correct 7 ms 5220 KB Output is correct
4 Correct 7 ms 5220 KB Output is correct
5 Correct 6 ms 5228 KB Output is correct
6 Correct 6 ms 5304 KB Output is correct
7 Correct 7 ms 5308 KB Output is correct
8 Correct 6 ms 5308 KB Output is correct
9 Correct 6 ms 5308 KB Output is correct
10 Correct 7 ms 5344 KB Output is correct
11 Correct 8 ms 5348 KB Output is correct
12 Correct 7 ms 5348 KB Output is correct
13 Correct 8 ms 5356 KB Output is correct
14 Correct 10 ms 5388 KB Output is correct
15 Correct 7 ms 5388 KB Output is correct
16 Correct 7 ms 5396 KB Output is correct
17 Correct 6 ms 5396 KB Output is correct
18 Correct 8 ms 5396 KB Output is correct
19 Correct 7 ms 5396 KB Output is correct
20 Correct 7 ms 5412 KB Output is correct
21 Correct 8 ms 5432 KB Output is correct
22 Correct 540 ms 10992 KB Output is correct
23 Correct 514 ms 10992 KB Output is correct
24 Correct 537 ms 10992 KB Output is correct
25 Correct 535 ms 10992 KB Output is correct
26 Correct 206 ms 10992 KB Output is correct
27 Correct 538 ms 10992 KB Output is correct
28 Correct 117 ms 10992 KB Output is correct
29 Correct 217 ms 10992 KB Output is correct
30 Correct 252 ms 10992 KB Output is correct
31 Correct 387 ms 10992 KB Output is correct
32 Correct 440 ms 10992 KB Output is correct
33 Correct 560 ms 10992 KB Output is correct
34 Correct 356 ms 10992 KB Output is correct
35 Correct 402 ms 10992 KB Output is correct
36 Correct 471 ms 10992 KB Output is correct
37 Correct 390 ms 10992 KB Output is correct
38 Correct 293 ms 10992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
2 Correct 9 ms 5220 KB Output is correct
3 Correct 7 ms 5220 KB Output is correct
4 Correct 7 ms 5220 KB Output is correct
5 Correct 6 ms 5228 KB Output is correct
6 Correct 6 ms 5304 KB Output is correct
7 Correct 7 ms 5308 KB Output is correct
8 Correct 6 ms 5308 KB Output is correct
9 Correct 6 ms 5308 KB Output is correct
10 Correct 7 ms 5344 KB Output is correct
11 Correct 8 ms 5348 KB Output is correct
12 Correct 7 ms 5348 KB Output is correct
13 Correct 8 ms 5356 KB Output is correct
14 Correct 10 ms 5388 KB Output is correct
15 Correct 7 ms 5388 KB Output is correct
16 Correct 7 ms 5396 KB Output is correct
17 Correct 6 ms 5396 KB Output is correct
18 Correct 8 ms 5396 KB Output is correct
19 Correct 253 ms 12660 KB Output is correct
20 Correct 256 ms 13964 KB Output is correct
21 Correct 265 ms 15580 KB Output is correct
22 Correct 291 ms 16796 KB Output is correct
23 Correct 154 ms 18552 KB Output is correct
24 Correct 104 ms 19744 KB Output is correct
25 Correct 221 ms 25404 KB Output is correct
26 Correct 127 ms 25948 KB Output is correct
27 Correct 259 ms 26076 KB Output is correct
28 Correct 518 ms 36564 KB Output is correct
29 Correct 432 ms 36564 KB Output is correct
30 Correct 273 ms 36564 KB Output is correct
31 Correct 317 ms 36564 KB Output is correct
32 Correct 303 ms 36564 KB Output is correct
33 Correct 458 ms 36564 KB Output is correct
34 Correct 495 ms 36564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
2 Correct 9 ms 5220 KB Output is correct
3 Correct 7 ms 5220 KB Output is correct
4 Correct 7 ms 5220 KB Output is correct
5 Correct 6 ms 5228 KB Output is correct
6 Correct 6 ms 5304 KB Output is correct
7 Correct 7 ms 5308 KB Output is correct
8 Correct 6 ms 5308 KB Output is correct
9 Correct 6 ms 5308 KB Output is correct
10 Correct 7 ms 5344 KB Output is correct
11 Correct 8 ms 5348 KB Output is correct
12 Correct 7 ms 5348 KB Output is correct
13 Correct 8 ms 5356 KB Output is correct
14 Correct 10 ms 5388 KB Output is correct
15 Correct 7 ms 5388 KB Output is correct
16 Correct 7 ms 5396 KB Output is correct
17 Correct 6 ms 5396 KB Output is correct
18 Correct 8 ms 5396 KB Output is correct
19 Correct 7 ms 5396 KB Output is correct
20 Correct 7 ms 5412 KB Output is correct
21 Correct 8 ms 5432 KB Output is correct
22 Correct 540 ms 10992 KB Output is correct
23 Correct 514 ms 10992 KB Output is correct
24 Correct 537 ms 10992 KB Output is correct
25 Correct 535 ms 10992 KB Output is correct
26 Correct 206 ms 10992 KB Output is correct
27 Correct 538 ms 10992 KB Output is correct
28 Correct 117 ms 10992 KB Output is correct
29 Correct 217 ms 10992 KB Output is correct
30 Correct 252 ms 10992 KB Output is correct
31 Correct 387 ms 10992 KB Output is correct
32 Correct 440 ms 10992 KB Output is correct
33 Correct 560 ms 10992 KB Output is correct
34 Correct 356 ms 10992 KB Output is correct
35 Correct 402 ms 10992 KB Output is correct
36 Correct 471 ms 10992 KB Output is correct
37 Correct 390 ms 10992 KB Output is correct
38 Correct 293 ms 10992 KB Output is correct
39 Correct 253 ms 12660 KB Output is correct
40 Correct 256 ms 13964 KB Output is correct
41 Correct 265 ms 15580 KB Output is correct
42 Correct 291 ms 16796 KB Output is correct
43 Correct 154 ms 18552 KB Output is correct
44 Correct 104 ms 19744 KB Output is correct
45 Correct 221 ms 25404 KB Output is correct
46 Correct 127 ms 25948 KB Output is correct
47 Correct 259 ms 26076 KB Output is correct
48 Correct 518 ms 36564 KB Output is correct
49 Correct 432 ms 36564 KB Output is correct
50 Correct 273 ms 36564 KB Output is correct
51 Correct 317 ms 36564 KB Output is correct
52 Correct 303 ms 36564 KB Output is correct
53 Correct 458 ms 36564 KB Output is correct
54 Correct 495 ms 36564 KB Output is correct
55 Correct 45 ms 36564 KB Output is correct
56 Correct 26 ms 36564 KB Output is correct
57 Correct 129 ms 36564 KB Output is correct
58 Correct 54 ms 36564 KB Output is correct
59 Execution timed out 3061 ms 36564 KB Time limit exceeded
60 Halted 0 ms 0 KB -