답안 #93998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93998 2019-01-14T13:32:14 Z fjzzq2002 경주 (Race) (IOI11_race) C++14
100 / 100
1066 ms 52856 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
namespace Wrap
{
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
typedef long long ll;
Edgc
int n,K,mi=2e9;
int sz[SZ],son[SZ],dep[SZ];
ll d1[SZ];
void dfs(int x,int f=SZ-1)
{
	dep[x]=dep[f]+1;
	sz[x]=1; son[x]=SZ-1;
	for esb(x,e,b) if(b!=f)
	{
		d1[b]=d1[x]+vc[e]; dfs(b,x); sz[x]+=sz[b];
		if(sz[b]>sz[son[x]]) son[x]=b;
	}
}
map<ll,int> ms;
int&gp(ll x)
{
	if(!ms.count(x))
		return ms[x]=2e9;
	return ms[x];
}
ll L; int ca;
void qry_pnt(int g)
{
	//d1[g]+d1[?]-L=K
	ca=min(ca,gp(K+L-d1[g])+dep[g]);
}
void add_pnt(int g)
{
	auto&t=gp(d1[g]);
	t=min(t,dep[g]);
}
template<class T>
void go(int x,int f,T*fun)
{
	fun(x);
	for esb(x,e,b) if(b!=f) go(b,x,fun);
}
void dfs2(int x,int t,bool k=1,int f=SZ-1)
{
	for esb(x,e,b) if(b!=f&&b!=son[x]) dfs2(b,b,0,x);
	if(son[x]<=n) dfs2(son[x],t,1,x);
	L=d1[x]*2; ca=2e9;
	for esb(x,e,b) if(b!=f&&b!=son[x])
		go(b,x,qry_pnt),go(b,x,add_pnt);
	qry_pnt(x); add_pnt(x);
	mi=min(mi,ca-dep[x]*2);
	if(!k) ms.clear();
}
}
int best_path(int N, int K_, int H[][2], int L[])
{
	using namespace Wrap;
	K=K_; n=N; mi=2e9;
	for(int i=0;i<N-1;++i)
		adde(H[i][0],H[i][1],L[i]);
	dfs(0); dfs2(0,0);
	return (mi>1e9)?(-1):mi;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 372 KB Output is correct
21 Correct 3 ms 508 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 500 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 4 ms 632 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 3 ms 632 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 195 ms 7696 KB Output is correct
20 Correct 183 ms 7696 KB Output is correct
21 Correct 183 ms 7728 KB Output is correct
22 Correct 168 ms 7808 KB Output is correct
23 Correct 298 ms 8028 KB Output is correct
24 Correct 187 ms 7900 KB Output is correct
25 Correct 75 ms 11640 KB Output is correct
26 Correct 42 ms 13944 KB Output is correct
27 Correct 239 ms 15444 KB Output is correct
28 Correct 260 ms 52856 KB Output is correct
29 Correct 214 ms 51832 KB Output is correct
30 Correct 201 ms 15480 KB Output is correct
31 Correct 219 ms 15596 KB Output is correct
32 Correct 331 ms 15736 KB Output is correct
33 Correct 304 ms 15480 KB Output is correct
34 Correct 801 ms 41072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 372 KB Output is correct
21 Correct 3 ms 508 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 632 KB Output is correct
27 Correct 3 ms 500 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 632 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 4 ms 632 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 3 ms 632 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 632 KB Output is correct
39 Correct 195 ms 7696 KB Output is correct
40 Correct 183 ms 7696 KB Output is correct
41 Correct 183 ms 7728 KB Output is correct
42 Correct 168 ms 7808 KB Output is correct
43 Correct 298 ms 8028 KB Output is correct
44 Correct 187 ms 7900 KB Output is correct
45 Correct 75 ms 11640 KB Output is correct
46 Correct 42 ms 13944 KB Output is correct
47 Correct 239 ms 15444 KB Output is correct
48 Correct 260 ms 52856 KB Output is correct
49 Correct 214 ms 51832 KB Output is correct
50 Correct 201 ms 15480 KB Output is correct
51 Correct 219 ms 15596 KB Output is correct
52 Correct 331 ms 15736 KB Output is correct
53 Correct 304 ms 15480 KB Output is correct
54 Correct 801 ms 41072 KB Output is correct
55 Correct 21 ms 1660 KB Output is correct
56 Correct 13 ms 1272 KB Output is correct
57 Correct 123 ms 7668 KB Output is correct
58 Correct 48 ms 7348 KB Output is correct
59 Correct 140 ms 26204 KB Output is correct
60 Correct 330 ms 51788 KB Output is correct
61 Correct 345 ms 18652 KB Output is correct
62 Correct 213 ms 15716 KB Output is correct
63 Correct 270 ms 15736 KB Output is correct
64 Correct 1012 ms 29276 KB Output is correct
65 Correct 1066 ms 40824 KB Output is correct
66 Correct 326 ms 49860 KB Output is correct
67 Correct 162 ms 15736 KB Output is correct
68 Correct 540 ms 36180 KB Output is correct
69 Correct 557 ms 36636 KB Output is correct
70 Correct 521 ms 34652 KB Output is correct