답안 #255436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255436 2020-08-01T01:32:23 Z babo 꿈 (IOI13_dreaming) C++14
47 / 100
152 ms 30332 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#define LL long long

using namespace std;

vector<LL>v[100010],t[100010];
LL n,len;
LL diam;
multiset<LL>rad;

LL chk[100010];
LL ord[100010],ordend[100010],ordtop;

LL max2(LL a,LL b,LL c){
	if(a<=b&&a<=c) return b+c;
	if(b<=c&&b<=a) return c+a;
	if(c<=a&&c<=b) return a+b;
}

struct S{
	LL ma1,ma1d,ma2,ma2d;
	S(){
		ma1=ma1d=ma2=ma2d=0;
	}
	void insert(LL dist,LL loc){
		if(dist>=ma1)
		{
			ma2=ma1;
			ma2d=ma1d;
			ma1=dist;
			ma1d=loc;
		}
		else if(dist>=ma2)
		{
			ma2=dist;
			ma2d=loc;
		}
	}
}S[100010];

void dfs(LL x,LL bu){
	ordtop++;
	ord[x]=ordtop;
	LL i;
	S[x].insert(0,x);
	for(i=0;i<v[x].size();i++)
	{
		if(v[x][i]!=bu)
		{
			chk[v[x][i]]=1;
			dfs(v[x][i],x);
			S[x].insert(S[v[x][i]].ma1+t[x][i],S[v[x][i]].ma1d);
		}
	}
	diam=max(diam,S[x].ma1+S[x].ma2);
	ordend[x]=ordtop;
}

LL dfs2(LL x,LL bu,LL give){
	//printf("rad %lld %lld %lld (%lld %lld) (%lld %lld)\n",x,bu,give,S[x].ma1,S[x].ma1d,S[x].ma2,S[x].ma2d);
	LL i,ret=max(max(give,S[x].ma1),S[x].ma2);
	for(i=0;i<v[x].size();i++)
	{
		if(v[x][i]!=bu)
		{
			if(ord[v[x][i]]<=ord[S[x].ma1d]&&ord[S[x].ma1d]<=ordend[v[x][i]])
			{
				if(S[x].ma2d)
					ret=min(ret,dfs2(v[x][i],x,max(give,S[x].ma2)+t[x][i]));
				else ret=min(ret,dfs2(v[x][i],x,give+t[x][i]));
			}
			else
				ret=min(ret,dfs2(v[x][i],x,max(give,S[x].ma1)+t[x][i]));
		}
	}
	return ret;
}

void tree(LL x){
	chk[x]=1;
	dfs(x,-1);
	rad.insert(dfs2(x,-1,0));
}

int travelTime(int N,int M,int l,int A[],int B[],int T[]){
	LL i;
	n=N,len=l;
	for(i=0;i<M;i++)
	{
		v[A[i]].push_back(B[i]);
		v[B[i]].push_back(A[i]);
		t[A[i]].push_back(T[i]);
		t[B[i]].push_back(T[i]);
	}
	for(i=0;i<N;i++)
	{
		if(!chk[i])
			tree(i);
	}
	/*printf("%lld\n", diam);
	for(multiset<LL>::iterator it=rad.begin();it!=rad.end();it++)
		printf("%lld ",*it);
	puts("");*/
	if(rad.size()==1) return (int)diam;
	else return max((int)diam,(int)(len+*prev(rad.end())+*prev(prev((rad.end())))));
}

Compilation message

dreaming.cpp: In function 'void dfs(long long int, long long int)':
dreaming.cpp:47:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<v[x].size();i++)
          ~^~~~~~~~~~~~
dreaming.cpp: In function 'long long int dfs2(long long int, long long int, long long int)':
dreaming.cpp:63:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<v[x].size();i++)
          ~^~~~~~~~~~~~
dreaming.cpp: In function 'long long int max2(long long int, long long int, long long int)':
dreaming.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 22648 KB Output is correct
2 Correct 89 ms 23408 KB Output is correct
3 Correct 54 ms 20600 KB Output is correct
4 Correct 14 ms 10496 KB Output is correct
5 Correct 11 ms 9600 KB Output is correct
6 Correct 20 ms 11648 KB Output is correct
7 Correct 4 ms 8192 KB Output is correct
8 Correct 43 ms 14840 KB Output is correct
9 Correct 51 ms 18040 KB Output is correct
10 Correct 5 ms 8320 KB Output is correct
11 Correct 86 ms 19832 KB Output is correct
12 Correct 98 ms 21628 KB Output is correct
13 Correct 5 ms 8320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 22648 KB Output is correct
2 Correct 89 ms 23408 KB Output is correct
3 Correct 54 ms 20600 KB Output is correct
4 Correct 14 ms 10496 KB Output is correct
5 Correct 11 ms 9600 KB Output is correct
6 Correct 20 ms 11648 KB Output is correct
7 Correct 4 ms 8192 KB Output is correct
8 Correct 43 ms 14840 KB Output is correct
9 Correct 51 ms 18040 KB Output is correct
10 Correct 5 ms 8320 KB Output is correct
11 Correct 86 ms 19832 KB Output is correct
12 Correct 98 ms 21628 KB Output is correct
13 Correct 5 ms 8320 KB Output is correct
14 Correct 5 ms 8192 KB Output is correct
15 Correct 4 ms 8192 KB Output is correct
16 Correct 4 ms 8192 KB Output is correct
17 Correct 4 ms 8192 KB Output is correct
18 Correct 5 ms 8192 KB Output is correct
19 Correct 4 ms 8192 KB Output is correct
20 Correct 4 ms 8192 KB Output is correct
21 Correct 4 ms 8192 KB Output is correct
22 Correct 4 ms 8192 KB Output is correct
23 Correct 4 ms 8192 KB Output is correct
24 Correct 4 ms 8192 KB Output is correct
25 Correct 5 ms 8192 KB Output is correct
26 Correct 5 ms 8192 KB Output is correct
27 Correct 4 ms 8192 KB Output is correct
28 Correct 5 ms 8192 KB Output is correct
29 Correct 4 ms 8192 KB Output is correct
30 Correct 4 ms 8192 KB Output is correct
31 Correct 4 ms 8192 KB Output is correct
32 Correct 4 ms 8192 KB Output is correct
33 Correct 5 ms 8192 KB Output is correct
34 Correct 4 ms 8192 KB Output is correct
35 Correct 4 ms 8192 KB Output is correct
36 Correct 5 ms 8212 KB Output is correct
37 Correct 4 ms 8192 KB Output is correct
38 Correct 4 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 22648 KB Output is correct
2 Correct 89 ms 23408 KB Output is correct
3 Correct 54 ms 20600 KB Output is correct
4 Correct 14 ms 10496 KB Output is correct
5 Correct 11 ms 9600 KB Output is correct
6 Correct 20 ms 11648 KB Output is correct
7 Correct 4 ms 8192 KB Output is correct
8 Correct 43 ms 14840 KB Output is correct
9 Correct 51 ms 18040 KB Output is correct
10 Correct 5 ms 8320 KB Output is correct
11 Correct 86 ms 19832 KB Output is correct
12 Correct 98 ms 21628 KB Output is correct
13 Correct 5 ms 8320 KB Output is correct
14 Correct 5 ms 8192 KB Output is correct
15 Correct 4 ms 8192 KB Output is correct
16 Correct 4 ms 8192 KB Output is correct
17 Correct 4 ms 8192 KB Output is correct
18 Correct 5 ms 8192 KB Output is correct
19 Correct 4 ms 8192 KB Output is correct
20 Correct 4 ms 8192 KB Output is correct
21 Correct 4 ms 8192 KB Output is correct
22 Correct 4 ms 8192 KB Output is correct
23 Correct 4 ms 8192 KB Output is correct
24 Correct 4 ms 8192 KB Output is correct
25 Correct 5 ms 8192 KB Output is correct
26 Correct 5 ms 8192 KB Output is correct
27 Correct 4 ms 8192 KB Output is correct
28 Correct 5 ms 8192 KB Output is correct
29 Correct 4 ms 8192 KB Output is correct
30 Correct 4 ms 8192 KB Output is correct
31 Correct 4 ms 8192 KB Output is correct
32 Correct 4 ms 8192 KB Output is correct
33 Correct 5 ms 8192 KB Output is correct
34 Correct 4 ms 8192 KB Output is correct
35 Correct 4 ms 8192 KB Output is correct
36 Correct 5 ms 8212 KB Output is correct
37 Correct 4 ms 8192 KB Output is correct
38 Correct 4 ms 8192 KB Output is correct
39 Correct 83 ms 23800 KB Output is correct
40 Correct 87 ms 23412 KB Output is correct
41 Correct 55 ms 20600 KB Output is correct
42 Correct 13 ms 10496 KB Output is correct
43 Correct 5 ms 8192 KB Output is correct
44 Correct 5 ms 8192 KB Output is correct
45 Correct 4 ms 8192 KB Output is correct
46 Correct 4 ms 8192 KB Output is correct
47 Correct 6 ms 8192 KB Output is correct
48 Correct 4 ms 8192 KB Output is correct
49 Correct 4 ms 8192 KB Output is correct
50 Correct 4 ms 8192 KB Output is correct
51 Correct 5 ms 8192 KB Output is correct
52 Correct 4 ms 8192 KB Output is correct
53 Correct 4 ms 8192 KB Output is correct
54 Correct 5 ms 8192 KB Output is correct
55 Correct 5 ms 8192 KB Output is correct
56 Correct 5 ms 8192 KB Output is correct
57 Correct 134 ms 20984 KB Output is correct
58 Correct 131 ms 20984 KB Output is correct
59 Correct 141 ms 20856 KB Output is correct
60 Correct 133 ms 20728 KB Output is correct
61 Correct 133 ms 20856 KB Output is correct
62 Correct 149 ms 20844 KB Output is correct
63 Correct 126 ms 20396 KB Output is correct
64 Correct 114 ms 20344 KB Output is correct
65 Correct 144 ms 20600 KB Output is correct
66 Correct 151 ms 20600 KB Output is correct
67 Correct 148 ms 20728 KB Output is correct
68 Correct 152 ms 20912 KB Output is correct
69 Correct 138 ms 21112 KB Output is correct
70 Correct 142 ms 21112 KB Output is correct
71 Correct 4 ms 8192 KB Output is correct
72 Correct 6 ms 8576 KB Output is correct
73 Correct 6 ms 8576 KB Output is correct
74 Correct 6 ms 8576 KB Output is correct
75 Correct 7 ms 8576 KB Output is correct
76 Correct 6 ms 8576 KB Output is correct
77 Correct 6 ms 8576 KB Output is correct
78 Correct 6 ms 8576 KB Output is correct
79 Correct 6 ms 8576 KB Output is correct
80 Correct 126 ms 20732 KB Output is correct
81 Correct 128 ms 20728 KB Output is correct
82 Correct 128 ms 20856 KB Output is correct
83 Correct 124 ms 20984 KB Output is correct
84 Correct 6 ms 8448 KB Output is correct
85 Correct 6 ms 8448 KB Output is correct
86 Correct 6 ms 8448 KB Output is correct
87 Correct 6 ms 8448 KB Output is correct
88 Correct 6 ms 8448 KB Output is correct
89 Correct 6 ms 8448 KB Output is correct
90 Correct 6 ms 8448 KB Output is correct
91 Correct 6 ms 8576 KB Output is correct
92 Correct 6 ms 8448 KB Output is correct
93 Correct 6 ms 8448 KB Output is correct
94 Correct 4 ms 8192 KB Output is correct
95 Correct 5 ms 8192 KB Output is correct
96 Correct 5 ms 8192 KB Output is correct
97 Correct 5 ms 8192 KB Output is correct
98 Correct 4 ms 8192 KB Output is correct
99 Correct 4 ms 8192 KB Output is correct
100 Correct 4 ms 8192 KB Output is correct
101 Correct 5 ms 8192 KB Output is correct
102 Correct 4 ms 8320 KB Output is correct
103 Correct 4 ms 8192 KB Output is correct
104 Correct 11 ms 9600 KB Output is correct
105 Correct 20 ms 11648 KB Output is correct
106 Correct 5 ms 8208 KB Output is correct
107 Correct 38 ms 14720 KB Output is correct
108 Correct 51 ms 18040 KB Output is correct
109 Correct 5 ms 8320 KB Output is correct
110 Correct 86 ms 19832 KB Output is correct
111 Correct 122 ms 21636 KB Output is correct
112 Correct 5 ms 8320 KB Output is correct
113 Correct 151 ms 30332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 17528 KB Output is correct
2 Incorrect 51 ms 17656 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 22648 KB Output is correct
2 Correct 89 ms 23408 KB Output is correct
3 Correct 54 ms 20600 KB Output is correct
4 Correct 14 ms 10496 KB Output is correct
5 Correct 11 ms 9600 KB Output is correct
6 Correct 20 ms 11648 KB Output is correct
7 Correct 4 ms 8192 KB Output is correct
8 Correct 43 ms 14840 KB Output is correct
9 Correct 51 ms 18040 KB Output is correct
10 Correct 5 ms 8320 KB Output is correct
11 Correct 86 ms 19832 KB Output is correct
12 Correct 98 ms 21628 KB Output is correct
13 Correct 5 ms 8320 KB Output is correct
14 Correct 5 ms 8320 KB Output is correct
15 Correct 6 ms 8448 KB Output is correct
16 Correct 7 ms 8576 KB Output is correct
17 Correct 5 ms 8320 KB Output is correct
18 Correct 6 ms 8448 KB Output is correct
19 Correct 6 ms 8576 KB Output is correct
20 Incorrect 5 ms 8320 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 22648 KB Output is correct
2 Correct 89 ms 23408 KB Output is correct
3 Correct 54 ms 20600 KB Output is correct
4 Correct 14 ms 10496 KB Output is correct
5 Correct 11 ms 9600 KB Output is correct
6 Correct 20 ms 11648 KB Output is correct
7 Correct 4 ms 8192 KB Output is correct
8 Correct 43 ms 14840 KB Output is correct
9 Correct 51 ms 18040 KB Output is correct
10 Correct 5 ms 8320 KB Output is correct
11 Correct 86 ms 19832 KB Output is correct
12 Correct 98 ms 21628 KB Output is correct
13 Correct 5 ms 8320 KB Output is correct
14 Correct 5 ms 8192 KB Output is correct
15 Correct 4 ms 8192 KB Output is correct
16 Correct 4 ms 8192 KB Output is correct
17 Correct 4 ms 8192 KB Output is correct
18 Correct 5 ms 8192 KB Output is correct
19 Correct 4 ms 8192 KB Output is correct
20 Correct 4 ms 8192 KB Output is correct
21 Correct 4 ms 8192 KB Output is correct
22 Correct 4 ms 8192 KB Output is correct
23 Correct 4 ms 8192 KB Output is correct
24 Correct 4 ms 8192 KB Output is correct
25 Correct 5 ms 8192 KB Output is correct
26 Correct 5 ms 8192 KB Output is correct
27 Correct 4 ms 8192 KB Output is correct
28 Correct 5 ms 8192 KB Output is correct
29 Correct 4 ms 8192 KB Output is correct
30 Correct 4 ms 8192 KB Output is correct
31 Correct 4 ms 8192 KB Output is correct
32 Correct 4 ms 8192 KB Output is correct
33 Correct 5 ms 8192 KB Output is correct
34 Correct 4 ms 8192 KB Output is correct
35 Correct 4 ms 8192 KB Output is correct
36 Correct 5 ms 8212 KB Output is correct
37 Correct 4 ms 8192 KB Output is correct
38 Correct 4 ms 8192 KB Output is correct
39 Correct 83 ms 23800 KB Output is correct
40 Correct 87 ms 23412 KB Output is correct
41 Correct 55 ms 20600 KB Output is correct
42 Correct 13 ms 10496 KB Output is correct
43 Correct 5 ms 8192 KB Output is correct
44 Correct 5 ms 8192 KB Output is correct
45 Correct 4 ms 8192 KB Output is correct
46 Correct 4 ms 8192 KB Output is correct
47 Correct 6 ms 8192 KB Output is correct
48 Correct 4 ms 8192 KB Output is correct
49 Correct 4 ms 8192 KB Output is correct
50 Correct 4 ms 8192 KB Output is correct
51 Correct 5 ms 8192 KB Output is correct
52 Correct 4 ms 8192 KB Output is correct
53 Correct 4 ms 8192 KB Output is correct
54 Correct 5 ms 8192 KB Output is correct
55 Correct 5 ms 8192 KB Output is correct
56 Correct 5 ms 8192 KB Output is correct
57 Correct 134 ms 20984 KB Output is correct
58 Correct 131 ms 20984 KB Output is correct
59 Correct 141 ms 20856 KB Output is correct
60 Correct 133 ms 20728 KB Output is correct
61 Correct 133 ms 20856 KB Output is correct
62 Correct 149 ms 20844 KB Output is correct
63 Correct 126 ms 20396 KB Output is correct
64 Correct 114 ms 20344 KB Output is correct
65 Correct 144 ms 20600 KB Output is correct
66 Correct 151 ms 20600 KB Output is correct
67 Correct 148 ms 20728 KB Output is correct
68 Correct 152 ms 20912 KB Output is correct
69 Correct 138 ms 21112 KB Output is correct
70 Correct 142 ms 21112 KB Output is correct
71 Correct 4 ms 8192 KB Output is correct
72 Correct 6 ms 8576 KB Output is correct
73 Correct 6 ms 8576 KB Output is correct
74 Correct 6 ms 8576 KB Output is correct
75 Correct 7 ms 8576 KB Output is correct
76 Correct 6 ms 8576 KB Output is correct
77 Correct 6 ms 8576 KB Output is correct
78 Correct 6 ms 8576 KB Output is correct
79 Correct 6 ms 8576 KB Output is correct
80 Correct 126 ms 20732 KB Output is correct
81 Correct 128 ms 20728 KB Output is correct
82 Correct 128 ms 20856 KB Output is correct
83 Correct 124 ms 20984 KB Output is correct
84 Correct 6 ms 8448 KB Output is correct
85 Correct 6 ms 8448 KB Output is correct
86 Correct 6 ms 8448 KB Output is correct
87 Correct 6 ms 8448 KB Output is correct
88 Correct 6 ms 8448 KB Output is correct
89 Correct 6 ms 8448 KB Output is correct
90 Correct 6 ms 8448 KB Output is correct
91 Correct 6 ms 8576 KB Output is correct
92 Correct 6 ms 8448 KB Output is correct
93 Correct 6 ms 8448 KB Output is correct
94 Correct 4 ms 8192 KB Output is correct
95 Correct 5 ms 8192 KB Output is correct
96 Correct 5 ms 8192 KB Output is correct
97 Correct 5 ms 8192 KB Output is correct
98 Correct 4 ms 8192 KB Output is correct
99 Correct 4 ms 8192 KB Output is correct
100 Correct 4 ms 8192 KB Output is correct
101 Correct 5 ms 8192 KB Output is correct
102 Correct 4 ms 8320 KB Output is correct
103 Correct 4 ms 8192 KB Output is correct
104 Correct 11 ms 9600 KB Output is correct
105 Correct 20 ms 11648 KB Output is correct
106 Correct 5 ms 8208 KB Output is correct
107 Correct 38 ms 14720 KB Output is correct
108 Correct 51 ms 18040 KB Output is correct
109 Correct 5 ms 8320 KB Output is correct
110 Correct 86 ms 19832 KB Output is correct
111 Correct 122 ms 21636 KB Output is correct
112 Correct 5 ms 8320 KB Output is correct
113 Correct 151 ms 30332 KB Output is correct
114 Correct 49 ms 17528 KB Output is correct
115 Incorrect 51 ms 17656 KB Output isn't correct
116 Halted 0 ms 0 KB -