Submission #18622

# Submission time Handle Problem Language Result Execution time Memory
18622 2016-02-12T15:59:22 Z ggoh Race (IOI11_race) C++
100 / 100
603 ms 29820 KB
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<deque>
#include<vector>
int a,i,j,x,y,sz2,st2[200005],sz,len[1000005],st[200005],z,maxtree[200005],tot[200005],v[200005],t;
int ans,b;
struct A{
    int to,cost;
};
struct B{
    int ho,di;
}data[200005];
std::vector<A>G[200005];
void dfs(int p)
{
    tot[p]=1;
    v[p]=1;
    maxtree[p]=0;
    for(int k=0;k<G[p].size();k++)
    {
        if(v[G[p][k].to]==0)
        {
            dfs(G[p][k].to);
            tot[p]+=tot[G[p][k].to];
            maxtree[p]=std::max(maxtree[p],tot[G[p][k].to]);
        }
    }
    st[t++]=p;
}

void dfs2(int p,int how,int dis)
{
    v[p]=1;
    if(dis>b)return ;
    data[sz++]={how,dis};
    if(dis==b&&(ans==-1||ans>how))
    {
        ans=how;
    }
    for(int k=0;k<G[p].size();k++)
    {
        if(v[G[p][k].to]==0)
        {
            dfs2(G[p][k].to,how+1,dis+G[p][k].cost);
        }
    }
}
void f(int p)
{
    int u=0;
    t=0;
    dfs(p);
    for(int i=0;i<t;i++)
    {
        if(std::max(maxtree[st[i]],tot[p]-tot[st[i]])<=tot[p]/2)
        {
            u=st[i];
        }
        v[st[i]]=0;
    }
    v[u]=1;
    sz2=0;
    for(int i=0;i<G[u].size();i++)
    {
        if(v[G[u][i].to]==0)
        {
            sz=0;
            dfs2(G[u][i].to,1,G[u][i].cost);
            for(int j=0;j<sz;j++)
            {
                if(len[b-data[j].di]&&(ans==-1||len[b-data[j].di]+data[j].ho<ans))
                {
                    ans=len[b-data[j].di]+data[j].ho;
                }
            }
            for(int j=0;j<sz;j++)
            {
                if(len[data[j].di]==0||len[data[j].di]>data[j].ho)
                {
                    if(len[data[j].di]==0)st2[sz2++]=data[j].di;
                    len[data[j].di]=data[j].ho;
                }
            }
        }
    }
    for(int i=0;i<sz2;i++)len[st2[i]]=0;
    for(int i=0;i<t;i++)v[st[i]]=0;
    v[u]=1;
    for(int i=0;i<G[u].size();i++)
    {
        if(v[G[u][i].to]==0)f(G[u][i].to);
    }
}
int best_path(int N,int K,int H[][2],int L[])
{
    a=N;
    b=K;
    for(i=0;i<a-1;i++)
    {
        x=H[i][0]+1;
        y=H[i][1]+1;
        z=L[i];
        G[x].push_back({y,z});
        G[y].push_back({x,z});
    }
    ans=-1;
    f(1);
    return ans;
}

Compilation message

race.cpp: In function 'void dfs(int)':
race.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k=0;k<G[p].size();k++)
                 ~^~~~~~~~~~~~
race.cpp: In function 'void dfs2(int, int, int)':
race.cpp:41:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k=0;k<G[p].size();k++)
                 ~^~~~~~~~~~~~
race.cpp: In function 'void f(int)':
race.cpp:64:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<G[u].size();i++)
                 ~^~~~~~~~~~~~
race.cpp:90:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<G[u].size();i++)
                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 7 ms 5224 KB Output is correct
4 Correct 7 ms 5224 KB Output is correct
5 Correct 6 ms 5224 KB Output is correct
6 Correct 7 ms 5224 KB Output is correct
7 Correct 8 ms 5224 KB Output is correct
8 Correct 6 ms 5224 KB Output is correct
9 Correct 6 ms 5224 KB Output is correct
10 Correct 6 ms 5224 KB Output is correct
11 Correct 6 ms 5224 KB Output is correct
12 Correct 7 ms 5280 KB Output is correct
13 Correct 7 ms 5280 KB Output is correct
14 Correct 7 ms 5280 KB Output is correct
15 Correct 6 ms 5296 KB Output is correct
16 Correct 6 ms 5296 KB Output is correct
17 Correct 6 ms 5296 KB Output is correct
18 Correct 6 ms 5428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 7 ms 5224 KB Output is correct
4 Correct 7 ms 5224 KB Output is correct
5 Correct 6 ms 5224 KB Output is correct
6 Correct 7 ms 5224 KB Output is correct
7 Correct 8 ms 5224 KB Output is correct
8 Correct 6 ms 5224 KB Output is correct
9 Correct 6 ms 5224 KB Output is correct
10 Correct 6 ms 5224 KB Output is correct
11 Correct 6 ms 5224 KB Output is correct
12 Correct 7 ms 5280 KB Output is correct
13 Correct 7 ms 5280 KB Output is correct
14 Correct 7 ms 5280 KB Output is correct
15 Correct 6 ms 5296 KB Output is correct
16 Correct 6 ms 5296 KB Output is correct
17 Correct 6 ms 5296 KB Output is correct
18 Correct 6 ms 5428 KB Output is correct
19 Correct 6 ms 5428 KB Output is correct
20 Correct 5 ms 5428 KB Output is correct
21 Correct 7 ms 5480 KB Output is correct
22 Correct 9 ms 7932 KB Output is correct
23 Correct 10 ms 7932 KB Output is correct
24 Correct 10 ms 8188 KB Output is correct
25 Correct 10 ms 8188 KB Output is correct
26 Correct 8 ms 8188 KB Output is correct
27 Correct 7 ms 8188 KB Output is correct
28 Correct 8 ms 8188 KB Output is correct
29 Correct 8 ms 8188 KB Output is correct
30 Correct 7 ms 8188 KB Output is correct
31 Correct 12 ms 8188 KB Output is correct
32 Correct 10 ms 8188 KB Output is correct
33 Correct 10 ms 8188 KB Output is correct
34 Correct 10 ms 8188 KB Output is correct
35 Correct 11 ms 8316 KB Output is correct
36 Correct 10 ms 8572 KB Output is correct
37 Correct 9 ms 8572 KB Output is correct
38 Correct 7 ms 8572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 7 ms 5224 KB Output is correct
4 Correct 7 ms 5224 KB Output is correct
5 Correct 6 ms 5224 KB Output is correct
6 Correct 7 ms 5224 KB Output is correct
7 Correct 8 ms 5224 KB Output is correct
8 Correct 6 ms 5224 KB Output is correct
9 Correct 6 ms 5224 KB Output is correct
10 Correct 6 ms 5224 KB Output is correct
11 Correct 6 ms 5224 KB Output is correct
12 Correct 7 ms 5280 KB Output is correct
13 Correct 7 ms 5280 KB Output is correct
14 Correct 7 ms 5280 KB Output is correct
15 Correct 6 ms 5296 KB Output is correct
16 Correct 6 ms 5296 KB Output is correct
17 Correct 6 ms 5296 KB Output is correct
18 Correct 6 ms 5428 KB Output is correct
19 Correct 165 ms 11772 KB Output is correct
20 Correct 162 ms 11772 KB Output is correct
21 Correct 184 ms 11948 KB Output is correct
22 Correct 179 ms 12208 KB Output is correct
23 Correct 128 ms 12208 KB Output is correct
24 Correct 146 ms 12208 KB Output is correct
25 Correct 310 ms 13804 KB Output is correct
26 Correct 104 ms 16224 KB Output is correct
27 Correct 217 ms 18336 KB Output is correct
28 Correct 396 ms 26424 KB Output is correct
29 Correct 441 ms 26424 KB Output is correct
30 Correct 252 ms 26424 KB Output is correct
31 Correct 260 ms 26424 KB Output is correct
32 Correct 281 ms 26424 KB Output is correct
33 Correct 390 ms 26424 KB Output is correct
34 Correct 406 ms 26424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5224 KB Output is correct
3 Correct 7 ms 5224 KB Output is correct
4 Correct 7 ms 5224 KB Output is correct
5 Correct 6 ms 5224 KB Output is correct
6 Correct 7 ms 5224 KB Output is correct
7 Correct 8 ms 5224 KB Output is correct
8 Correct 6 ms 5224 KB Output is correct
9 Correct 6 ms 5224 KB Output is correct
10 Correct 6 ms 5224 KB Output is correct
11 Correct 6 ms 5224 KB Output is correct
12 Correct 7 ms 5280 KB Output is correct
13 Correct 7 ms 5280 KB Output is correct
14 Correct 7 ms 5280 KB Output is correct
15 Correct 6 ms 5296 KB Output is correct
16 Correct 6 ms 5296 KB Output is correct
17 Correct 6 ms 5296 KB Output is correct
18 Correct 6 ms 5428 KB Output is correct
19 Correct 6 ms 5428 KB Output is correct
20 Correct 5 ms 5428 KB Output is correct
21 Correct 7 ms 5480 KB Output is correct
22 Correct 9 ms 7932 KB Output is correct
23 Correct 10 ms 7932 KB Output is correct
24 Correct 10 ms 8188 KB Output is correct
25 Correct 10 ms 8188 KB Output is correct
26 Correct 8 ms 8188 KB Output is correct
27 Correct 7 ms 8188 KB Output is correct
28 Correct 8 ms 8188 KB Output is correct
29 Correct 8 ms 8188 KB Output is correct
30 Correct 7 ms 8188 KB Output is correct
31 Correct 12 ms 8188 KB Output is correct
32 Correct 10 ms 8188 KB Output is correct
33 Correct 10 ms 8188 KB Output is correct
34 Correct 10 ms 8188 KB Output is correct
35 Correct 11 ms 8316 KB Output is correct
36 Correct 10 ms 8572 KB Output is correct
37 Correct 9 ms 8572 KB Output is correct
38 Correct 7 ms 8572 KB Output is correct
39 Correct 165 ms 11772 KB Output is correct
40 Correct 162 ms 11772 KB Output is correct
41 Correct 184 ms 11948 KB Output is correct
42 Correct 179 ms 12208 KB Output is correct
43 Correct 128 ms 12208 KB Output is correct
44 Correct 146 ms 12208 KB Output is correct
45 Correct 310 ms 13804 KB Output is correct
46 Correct 104 ms 16224 KB Output is correct
47 Correct 217 ms 18336 KB Output is correct
48 Correct 396 ms 26424 KB Output is correct
49 Correct 441 ms 26424 KB Output is correct
50 Correct 252 ms 26424 KB Output is correct
51 Correct 260 ms 26424 KB Output is correct
52 Correct 281 ms 26424 KB Output is correct
53 Correct 390 ms 26424 KB Output is correct
54 Correct 406 ms 26424 KB Output is correct
55 Correct 20 ms 26424 KB Output is correct
56 Correct 18 ms 26424 KB Output is correct
57 Correct 102 ms 26424 KB Output is correct
58 Correct 51 ms 26424 KB Output is correct
59 Correct 108 ms 26424 KB Output is correct
60 Correct 603 ms 29820 KB Output is correct
61 Correct 233 ms 29820 KB Output is correct
62 Correct 238 ms 29820 KB Output is correct
63 Correct 318 ms 29820 KB Output is correct
64 Correct 559 ms 29820 KB Output is correct
65 Correct 332 ms 29820 KB Output is correct
66 Correct 503 ms 29820 KB Output is correct
67 Correct 164 ms 29820 KB Output is correct
68 Correct 327 ms 29820 KB Output is correct
69 Correct 326 ms 29820 KB Output is correct
70 Correct 312 ms 29820 KB Output is correct