답안 #364738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364738 2021-02-09T20:57:21 Z ogibogi2004 경주 (Race) (IOI11_race) C++14
100 / 100
954 ms 54252 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=2e5+6;
const int MAXK=1e6+6;
vector<pair<int,ll> >g[MAXN];
vector<int>g1[MAXN];
int n,k;
bool f[MAXN];
int st[MAXN],root;
ll minh[MAXK],ans=MAXN+2;
int rankc[MAXN];
vector<int>updated;
void dfs(int u,int p)
{
	for(auto v:g[u])
	{
		if(v.first==p)continue;
		dfs(v.first,u);
	}
}
void dfs1(int u,int p)
{
	st[u]=1;
	for(auto v:g[u])
	{
		if(v.first==p)continue;
		if(f[v.first])continue;
		dfs1(v.first,u);
		st[u]+=st[v.first];
	}
}
int find(int u,int p,int t)
{
	for(auto v:g[u])
	{
		if(v.first==p)continue;
		if(f[v.first])continue;
		if(st[v.first]>t/2)
		{
			return find(v.first,u,t);
		}
	}
	return u;
}
void decompose(int u,int p)
{
	dfs1(u,-1);
	int c=find(u,-1,st[u]);
	if(p!=-1)
	{
		rankc[c]=rankc[p]+1;
		g1[p].push_back(c);
	}
	else 
	{
		root=c;
		rankc[c]=1;
	}
	f[c]=1;
	for(auto v:g[c])
	{
		if(f[v.first])continue;
		decompose(v.first,c);
	}
}
void dfs2(int u,int p,int maxrank,int d,int d1)
{
	updated.push_back(d1);
	minh[d1]=min(minh[d1],(ll)d);
	for(auto v:g[u])
	{
		if(v.first==p)continue;
		if(rankc[v.first]>=maxrank)continue;
		if(v.second+d1>k)continue;
		dfs2(v.first,u,maxrank,d+1,d1+v.second);
	}
}
void dfs3(int u,int p,int maxrank,int d,int d1)
{
	ans=min(ans,minh[k-d1]+d);
	for(auto v:g[u])
	{
		if(v.first==p)continue;
		if(rankc[v.first]>=maxrank)continue;
		if(v.second+d1>k)continue;
		dfs3(v.first,u,maxrank,d+1,d1+v.second);
	}
}
int best_path(int N, int K, int H[][2], int L[])
{
	memset(f,0,sizeof(f));
	n=N;k=K;
	for(int i=1;i<=n;++i)g[i].clear();
	for(int i=0;i<N-1;++i)
	{
		g[H[i][0]+1].push_back({H[i][1]+1,L[i]});
		g[H[i][1]+1].push_back({H[i][0]+1,L[i]});
	}
	ans=n+2;
	dfs(1,0);
	decompose(1,-1);
	for(int i=0;i<MAXK;++i)minh[i]=n+2;
	for(int i=1;i<=n;++i)rankc[i]=n-rankc[i]+1;
	for(int i=1;i<=n;++i)
	{
		minh[0]=0;
		updated.clear();
		updated.push_back(0);
		for(auto v:g[i])
		{
			if(rankc[v.first]>=rankc[i])continue;
			if(v.second>k)continue;
			dfs3(v.first,i,rankc[i],1,v.second);
			dfs2(v.first,i,rankc[i],1,v.second);
		}
		for(auto u:updated)minh[u]=n+2;
	}
	if(ans>n)return -1;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17772 KB Output is correct
2 Correct 12 ms 17772 KB Output is correct
3 Correct 12 ms 17772 KB Output is correct
4 Correct 14 ms 17772 KB Output is correct
5 Correct 12 ms 17772 KB Output is correct
6 Correct 14 ms 17772 KB Output is correct
7 Correct 14 ms 17772 KB Output is correct
8 Correct 14 ms 17772 KB Output is correct
9 Correct 12 ms 17772 KB Output is correct
10 Correct 12 ms 17772 KB Output is correct
11 Correct 13 ms 17772 KB Output is correct
12 Correct 12 ms 17772 KB Output is correct
13 Correct 12 ms 17772 KB Output is correct
14 Correct 12 ms 17772 KB Output is correct
15 Correct 13 ms 17772 KB Output is correct
16 Correct 12 ms 17772 KB Output is correct
17 Correct 15 ms 17772 KB Output is correct
18 Correct 12 ms 17772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17772 KB Output is correct
2 Correct 12 ms 17772 KB Output is correct
3 Correct 12 ms 17772 KB Output is correct
4 Correct 14 ms 17772 KB Output is correct
5 Correct 12 ms 17772 KB Output is correct
6 Correct 14 ms 17772 KB Output is correct
7 Correct 14 ms 17772 KB Output is correct
8 Correct 14 ms 17772 KB Output is correct
9 Correct 12 ms 17772 KB Output is correct
10 Correct 12 ms 17772 KB Output is correct
11 Correct 13 ms 17772 KB Output is correct
12 Correct 12 ms 17772 KB Output is correct
13 Correct 12 ms 17772 KB Output is correct
14 Correct 12 ms 17772 KB Output is correct
15 Correct 13 ms 17772 KB Output is correct
16 Correct 12 ms 17772 KB Output is correct
17 Correct 15 ms 17772 KB Output is correct
18 Correct 12 ms 17772 KB Output is correct
19 Correct 11 ms 17772 KB Output is correct
20 Correct 13 ms 17772 KB Output is correct
21 Correct 12 ms 17900 KB Output is correct
22 Correct 18 ms 17900 KB Output is correct
23 Correct 16 ms 17900 KB Output is correct
24 Correct 11 ms 17900 KB Output is correct
25 Correct 12 ms 18048 KB Output is correct
26 Correct 12 ms 17900 KB Output is correct
27 Correct 11 ms 17900 KB Output is correct
28 Correct 12 ms 17900 KB Output is correct
29 Correct 14 ms 17900 KB Output is correct
30 Correct 13 ms 17900 KB Output is correct
31 Correct 14 ms 17900 KB Output is correct
32 Correct 14 ms 17900 KB Output is correct
33 Correct 13 ms 17900 KB Output is correct
34 Correct 13 ms 17900 KB Output is correct
35 Correct 14 ms 17900 KB Output is correct
36 Correct 13 ms 17900 KB Output is correct
37 Correct 13 ms 17900 KB Output is correct
38 Correct 13 ms 17900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17772 KB Output is correct
2 Correct 12 ms 17772 KB Output is correct
3 Correct 12 ms 17772 KB Output is correct
4 Correct 14 ms 17772 KB Output is correct
5 Correct 12 ms 17772 KB Output is correct
6 Correct 14 ms 17772 KB Output is correct
7 Correct 14 ms 17772 KB Output is correct
8 Correct 14 ms 17772 KB Output is correct
9 Correct 12 ms 17772 KB Output is correct
10 Correct 12 ms 17772 KB Output is correct
11 Correct 13 ms 17772 KB Output is correct
12 Correct 12 ms 17772 KB Output is correct
13 Correct 12 ms 17772 KB Output is correct
14 Correct 12 ms 17772 KB Output is correct
15 Correct 13 ms 17772 KB Output is correct
16 Correct 12 ms 17772 KB Output is correct
17 Correct 15 ms 17772 KB Output is correct
18 Correct 12 ms 17772 KB Output is correct
19 Correct 271 ms 26396 KB Output is correct
20 Correct 271 ms 27692 KB Output is correct
21 Correct 323 ms 28012 KB Output is correct
22 Correct 285 ms 28400 KB Output is correct
23 Correct 142 ms 28140 KB Output is correct
24 Correct 106 ms 26476 KB Output is correct
25 Correct 254 ms 32004 KB Output is correct
26 Correct 128 ms 36328 KB Output is correct
27 Correct 244 ms 37612 KB Output is correct
28 Correct 454 ms 53996 KB Output is correct
29 Correct 455 ms 52716 KB Output is correct
30 Correct 244 ms 37484 KB Output is correct
31 Correct 261 ms 37612 KB Output is correct
32 Correct 424 ms 37496 KB Output is correct
33 Correct 480 ms 37740 KB Output is correct
34 Correct 304 ms 38508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17772 KB Output is correct
2 Correct 12 ms 17772 KB Output is correct
3 Correct 12 ms 17772 KB Output is correct
4 Correct 14 ms 17772 KB Output is correct
5 Correct 12 ms 17772 KB Output is correct
6 Correct 14 ms 17772 KB Output is correct
7 Correct 14 ms 17772 KB Output is correct
8 Correct 14 ms 17772 KB Output is correct
9 Correct 12 ms 17772 KB Output is correct
10 Correct 12 ms 17772 KB Output is correct
11 Correct 13 ms 17772 KB Output is correct
12 Correct 12 ms 17772 KB Output is correct
13 Correct 12 ms 17772 KB Output is correct
14 Correct 12 ms 17772 KB Output is correct
15 Correct 13 ms 17772 KB Output is correct
16 Correct 12 ms 17772 KB Output is correct
17 Correct 15 ms 17772 KB Output is correct
18 Correct 12 ms 17772 KB Output is correct
19 Correct 11 ms 17772 KB Output is correct
20 Correct 13 ms 17772 KB Output is correct
21 Correct 12 ms 17900 KB Output is correct
22 Correct 18 ms 17900 KB Output is correct
23 Correct 16 ms 17900 KB Output is correct
24 Correct 11 ms 17900 KB Output is correct
25 Correct 12 ms 18048 KB Output is correct
26 Correct 12 ms 17900 KB Output is correct
27 Correct 11 ms 17900 KB Output is correct
28 Correct 12 ms 17900 KB Output is correct
29 Correct 14 ms 17900 KB Output is correct
30 Correct 13 ms 17900 KB Output is correct
31 Correct 14 ms 17900 KB Output is correct
32 Correct 14 ms 17900 KB Output is correct
33 Correct 13 ms 17900 KB Output is correct
34 Correct 13 ms 17900 KB Output is correct
35 Correct 14 ms 17900 KB Output is correct
36 Correct 13 ms 17900 KB Output is correct
37 Correct 13 ms 17900 KB Output is correct
38 Correct 13 ms 17900 KB Output is correct
39 Correct 271 ms 26396 KB Output is correct
40 Correct 271 ms 27692 KB Output is correct
41 Correct 323 ms 28012 KB Output is correct
42 Correct 285 ms 28400 KB Output is correct
43 Correct 142 ms 28140 KB Output is correct
44 Correct 106 ms 26476 KB Output is correct
45 Correct 254 ms 32004 KB Output is correct
46 Correct 128 ms 36328 KB Output is correct
47 Correct 244 ms 37612 KB Output is correct
48 Correct 454 ms 53996 KB Output is correct
49 Correct 455 ms 52716 KB Output is correct
50 Correct 244 ms 37484 KB Output is correct
51 Correct 261 ms 37612 KB Output is correct
52 Correct 424 ms 37496 KB Output is correct
53 Correct 480 ms 37740 KB Output is correct
54 Correct 304 ms 38508 KB Output is correct
55 Correct 22 ms 18796 KB Output is correct
56 Correct 24 ms 18796 KB Output is correct
57 Correct 111 ms 28776 KB Output is correct
58 Correct 56 ms 26716 KB Output is correct
59 Correct 128 ms 36328 KB Output is correct
60 Correct 795 ms 54252 KB Output is correct
61 Correct 276 ms 37996 KB Output is correct
62 Correct 271 ms 38628 KB Output is correct
63 Correct 532 ms 38756 KB Output is correct
64 Correct 954 ms 39396 KB Output is correct
65 Correct 363 ms 38764 KB Output is correct
66 Correct 796 ms 50412 KB Output is correct
67 Correct 176 ms 37540 KB Output is correct
68 Correct 459 ms 38208 KB Output is correct
69 Correct 485 ms 37992 KB Output is correct
70 Correct 415 ms 37236 KB Output is correct