Submission #14769

# Submission time Handle Problem Language Result Execution time Memory
14769 2015-06-22T04:34:37 Z progressive Dreaming (IOI13_dreaming) C++14
47 / 100
102 ms 16116 KB
#include "dreaming.h"
#include <vector>
#include <algorithm>
using namespace std;

static const int MAXN=100100;
static vector<pair<int,int> > conn[MAXN];
static int color[MAXN];
static int tp=0;
static int hdist[MAXN];
static int dist[MAXN];
static int parent[MAXN];
static vector<int> samecolor[MAXN];
static vector<int> radius;
void colordfs(int a,int pa,int c)
{
	color[a]=c;
	samecolor[c].push_back(a);
	for(int i=0;i<conn[a].size();i++)
	{
		int target=conn[a][i].first;
		if(target==pa) continue;
		hdist[target]=hdist[a]+conn[a][i].second;
		colordfs(target,a,c);
	}
}
void dfs(int a,int pa)
{
	parent[a]=pa;
	for(int i=0;i<conn[a].size();i++)
	{
		int target=conn[a][i].first;
		if(target==pa) continue;
		dist[target]=dist[a]+conn[a][i].second;
		dfs(target,a);
	}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
	for(int i=0;i<M;i++)
	{
		conn[A[i]].push_back(make_pair(B[i],T[i]));
		conn[B[i]].push_back(make_pair(A[i],T[i]));
	}
	for(int i=0;i<N;i++)
		if(!color[i]) colordfs(i,-1,++tp);
	int retval=0;
	for(int i=1;i<=tp;i++)
	{
		int furthest=samecolor[i][0];
		for(int j=0;j<samecolor[i].size();j++)
			if(hdist[furthest]<hdist[samecolor[i][j]]) furthest=samecolor[i][j];
		dfs(furthest,-1);
		int dia=furthest;
		for(int j=0;j<samecolor[i].size();j++)
			if(dist[dia]<dist[samecolor[i][j]]) dia=samecolor[i][j];
		int radii=dist[dia];
		int res=radii;
		retval=max(retval,radii);
		while(dia!=-1)
		{
			res=min(res,max(radii-dist[dia],dist[dia]));
			dia=parent[dia];
		}
		radius.push_back(res);
	}
	sort(radius.begin(),radius.end());
	reverse(radius.begin(),radius.end());
	if(tp==2) retval=max(retval, radius[0]+radius[1]+L);
	else retval=max(retval,max(radius[0]+radius[1]+L,radius[1]+radius[2]+2*L));
	return retval;
}

Compilation message

dreaming.cpp: In function 'void colordfs(int, int, int)':
dreaming.cpp:19:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<conn[a].size();i++)
              ~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<conn[a].size();i++)
              ~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:51:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<samecolor[i].size();j++)
               ~^~~~~~~~~~~~~~~~~~~~
dreaming.cpp:55:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<samecolor[i].size();j++)
               ~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 87 ms 15092 KB Output is correct
2 Correct 62 ms 15184 KB Output is correct
3 Correct 42 ms 11636 KB Output is correct
4 Correct 13 ms 6656 KB Output is correct
5 Correct 11 ms 5888 KB Output is correct
6 Correct 18 ms 7424 KB Output is correct
7 Correct 5 ms 5120 KB Output is correct
8 Correct 31 ms 8824 KB Output is correct
9 Correct 36 ms 10112 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 61 ms 11768 KB Output is correct
12 Correct 67 ms 13396 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 15092 KB Output is correct
2 Correct 62 ms 15184 KB Output is correct
3 Correct 42 ms 11636 KB Output is correct
4 Correct 13 ms 6656 KB Output is correct
5 Correct 11 ms 5888 KB Output is correct
6 Correct 18 ms 7424 KB Output is correct
7 Correct 5 ms 5120 KB Output is correct
8 Correct 31 ms 8824 KB Output is correct
9 Correct 36 ms 10112 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 61 ms 11768 KB Output is correct
12 Correct 67 ms 13396 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 6 ms 4992 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 6 ms 4992 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 5120 KB Output is correct
20 Correct 6 ms 5164 KB Output is correct
21 Correct 6 ms 5072 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 4992 KB Output is correct
24 Correct 6 ms 5092 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 5 ms 4992 KB Output is correct
27 Correct 5 ms 4992 KB Output is correct
28 Correct 5 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 6 ms 5120 KB Output is correct
31 Correct 6 ms 4992 KB Output is correct
32 Correct 6 ms 4992 KB Output is correct
33 Correct 6 ms 5120 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 5 ms 4992 KB Output is correct
36 Correct 5 ms 4992 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 6 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 15092 KB Output is correct
2 Correct 62 ms 15184 KB Output is correct
3 Correct 42 ms 11636 KB Output is correct
4 Correct 13 ms 6656 KB Output is correct
5 Correct 11 ms 5888 KB Output is correct
6 Correct 18 ms 7424 KB Output is correct
7 Correct 5 ms 5120 KB Output is correct
8 Correct 31 ms 8824 KB Output is correct
9 Correct 36 ms 10112 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 61 ms 11768 KB Output is correct
12 Correct 67 ms 13396 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 6 ms 4992 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 6 ms 4992 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 5120 KB Output is correct
20 Correct 6 ms 5164 KB Output is correct
21 Correct 6 ms 5072 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 4992 KB Output is correct
24 Correct 6 ms 5092 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 5 ms 4992 KB Output is correct
27 Correct 5 ms 4992 KB Output is correct
28 Correct 5 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 6 ms 5120 KB Output is correct
31 Correct 6 ms 4992 KB Output is correct
32 Correct 6 ms 4992 KB Output is correct
33 Correct 6 ms 5120 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 5 ms 4992 KB Output is correct
36 Correct 5 ms 4992 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 6 ms 5120 KB Output is correct
39 Correct 65 ms 15136 KB Output is correct
40 Correct 61 ms 15100 KB Output is correct
41 Correct 40 ms 11636 KB Output is correct
42 Correct 14 ms 6656 KB Output is correct
43 Correct 5 ms 5120 KB Output is correct
44 Correct 6 ms 5120 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 6 ms 5120 KB Output is correct
47 Correct 6 ms 5120 KB Output is correct
48 Correct 5 ms 4992 KB Output is correct
49 Correct 6 ms 5120 KB Output is correct
50 Correct 5 ms 4992 KB Output is correct
51 Correct 5 ms 5120 KB Output is correct
52 Correct 5 ms 4992 KB Output is correct
53 Correct 6 ms 5120 KB Output is correct
54 Correct 6 ms 4992 KB Output is correct
55 Correct 5 ms 4992 KB Output is correct
56 Correct 6 ms 5120 KB Output is correct
57 Correct 97 ms 12244 KB Output is correct
58 Correct 75 ms 12248 KB Output is correct
59 Correct 84 ms 12116 KB Output is correct
60 Correct 82 ms 12148 KB Output is correct
61 Correct 86 ms 12016 KB Output is correct
62 Correct 80 ms 12148 KB Output is correct
63 Correct 77 ms 12020 KB Output is correct
64 Correct 93 ms 12048 KB Output is correct
65 Correct 102 ms 11892 KB Output is correct
66 Correct 90 ms 11892 KB Output is correct
67 Correct 77 ms 12084 KB Output is correct
68 Correct 85 ms 12144 KB Output is correct
69 Correct 83 ms 12276 KB Output is correct
70 Correct 86 ms 12148 KB Output is correct
71 Correct 5 ms 4992 KB Output is correct
72 Correct 7 ms 5248 KB Output is correct
73 Correct 7 ms 5248 KB Output is correct
74 Correct 7 ms 5248 KB Output is correct
75 Correct 7 ms 5248 KB Output is correct
76 Correct 7 ms 5248 KB Output is correct
77 Correct 7 ms 5248 KB Output is correct
78 Correct 7 ms 5248 KB Output is correct
79 Correct 7 ms 5376 KB Output is correct
80 Correct 93 ms 12152 KB Output is correct
81 Correct 75 ms 12144 KB Output is correct
82 Correct 81 ms 12020 KB Output is correct
83 Correct 84 ms 12088 KB Output is correct
84 Correct 6 ms 5248 KB Output is correct
85 Correct 6 ms 5248 KB Output is correct
86 Correct 7 ms 5248 KB Output is correct
87 Correct 8 ms 5248 KB Output is correct
88 Correct 7 ms 5248 KB Output is correct
89 Correct 7 ms 5316 KB Output is correct
90 Correct 6 ms 5248 KB Output is correct
91 Correct 7 ms 5248 KB Output is correct
92 Correct 7 ms 5248 KB Output is correct
93 Correct 7 ms 5248 KB Output is correct
94 Correct 5 ms 5120 KB Output is correct
95 Correct 5 ms 4992 KB Output is correct
96 Correct 5 ms 4992 KB Output is correct
97 Correct 5 ms 5120 KB Output is correct
98 Correct 5 ms 4992 KB Output is correct
99 Correct 5 ms 4992 KB Output is correct
100 Correct 6 ms 4992 KB Output is correct
101 Correct 6 ms 5120 KB Output is correct
102 Correct 6 ms 4992 KB Output is correct
103 Correct 6 ms 5120 KB Output is correct
104 Correct 11 ms 5888 KB Output is correct
105 Correct 18 ms 7424 KB Output is correct
106 Correct 6 ms 5120 KB Output is correct
107 Correct 32 ms 8824 KB Output is correct
108 Correct 38 ms 10112 KB Output is correct
109 Correct 5 ms 5120 KB Output is correct
110 Correct 54 ms 11736 KB Output is correct
111 Correct 70 ms 13308 KB Output is correct
112 Correct 5 ms 5148 KB Output is correct
113 Correct 102 ms 16116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 11128 KB Output is correct
2 Correct 54 ms 11156 KB Output is correct
3 Correct 39 ms 11128 KB Output is correct
4 Correct 39 ms 11256 KB Output is correct
5 Correct 49 ms 11076 KB Output is correct
6 Correct 53 ms 11764 KB Output is correct
7 Correct 45 ms 11508 KB Output is correct
8 Correct 47 ms 11124 KB Output is correct
9 Correct 53 ms 11000 KB Output is correct
10 Correct 42 ms 11384 KB Output is correct
11 Correct 5 ms 4992 KB Output is correct
12 Correct 17 ms 10236 KB Output is correct
13 Correct 18 ms 10240 KB Output is correct
14 Correct 17 ms 10240 KB Output is correct
15 Correct 16 ms 10112 KB Output is correct
16 Correct 46 ms 10112 KB Output is correct
17 Correct 17 ms 9728 KB Output is correct
18 Correct 17 ms 10240 KB Output is correct
19 Correct 16 ms 10112 KB Output is correct
20 Incorrect 6 ms 4992 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 15092 KB Output is correct
2 Correct 62 ms 15184 KB Output is correct
3 Correct 42 ms 11636 KB Output is correct
4 Correct 13 ms 6656 KB Output is correct
5 Correct 11 ms 5888 KB Output is correct
6 Correct 18 ms 7424 KB Output is correct
7 Correct 5 ms 5120 KB Output is correct
8 Correct 31 ms 8824 KB Output is correct
9 Correct 36 ms 10112 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 61 ms 11768 KB Output is correct
12 Correct 67 ms 13396 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 7 ms 5220 KB Output is correct
16 Correct 7 ms 5248 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5248 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 6 ms 5120 KB Output is correct
22 Correct 7 ms 5248 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 6 ms 5120 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 6 ms 5120 KB Output is correct
27 Correct 5 ms 5120 KB Output is correct
28 Correct 6 ms 5120 KB Output is correct
29 Correct 6 ms 5120 KB Output is correct
30 Correct 7 ms 5120 KB Output is correct
31 Correct 5 ms 5120 KB Output is correct
32 Correct 6 ms 4992 KB Output is correct
33 Correct 6 ms 5120 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 5 ms 4992 KB Output is correct
36 Correct 5 ms 4992 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 5 ms 4992 KB Output is correct
39 Correct 5 ms 4992 KB Output is correct
40 Incorrect 5 ms 4992 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 15092 KB Output is correct
2 Correct 62 ms 15184 KB Output is correct
3 Correct 42 ms 11636 KB Output is correct
4 Correct 13 ms 6656 KB Output is correct
5 Correct 11 ms 5888 KB Output is correct
6 Correct 18 ms 7424 KB Output is correct
7 Correct 5 ms 5120 KB Output is correct
8 Correct 31 ms 8824 KB Output is correct
9 Correct 36 ms 10112 KB Output is correct
10 Correct 6 ms 5120 KB Output is correct
11 Correct 61 ms 11768 KB Output is correct
12 Correct 67 ms 13396 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 6 ms 4992 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 6 ms 4992 KB Output is correct
17 Correct 6 ms 5120 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 5120 KB Output is correct
20 Correct 6 ms 5164 KB Output is correct
21 Correct 6 ms 5072 KB Output is correct
22 Correct 6 ms 5120 KB Output is correct
23 Correct 6 ms 4992 KB Output is correct
24 Correct 6 ms 5092 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 5 ms 4992 KB Output is correct
27 Correct 5 ms 4992 KB Output is correct
28 Correct 5 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 6 ms 5120 KB Output is correct
31 Correct 6 ms 4992 KB Output is correct
32 Correct 6 ms 4992 KB Output is correct
33 Correct 6 ms 5120 KB Output is correct
34 Correct 6 ms 5120 KB Output is correct
35 Correct 5 ms 4992 KB Output is correct
36 Correct 5 ms 4992 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 6 ms 5120 KB Output is correct
39 Correct 65 ms 15136 KB Output is correct
40 Correct 61 ms 15100 KB Output is correct
41 Correct 40 ms 11636 KB Output is correct
42 Correct 14 ms 6656 KB Output is correct
43 Correct 5 ms 5120 KB Output is correct
44 Correct 6 ms 5120 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 6 ms 5120 KB Output is correct
47 Correct 6 ms 5120 KB Output is correct
48 Correct 5 ms 4992 KB Output is correct
49 Correct 6 ms 5120 KB Output is correct
50 Correct 5 ms 4992 KB Output is correct
51 Correct 5 ms 5120 KB Output is correct
52 Correct 5 ms 4992 KB Output is correct
53 Correct 6 ms 5120 KB Output is correct
54 Correct 6 ms 4992 KB Output is correct
55 Correct 5 ms 4992 KB Output is correct
56 Correct 6 ms 5120 KB Output is correct
57 Correct 97 ms 12244 KB Output is correct
58 Correct 75 ms 12248 KB Output is correct
59 Correct 84 ms 12116 KB Output is correct
60 Correct 82 ms 12148 KB Output is correct
61 Correct 86 ms 12016 KB Output is correct
62 Correct 80 ms 12148 KB Output is correct
63 Correct 77 ms 12020 KB Output is correct
64 Correct 93 ms 12048 KB Output is correct
65 Correct 102 ms 11892 KB Output is correct
66 Correct 90 ms 11892 KB Output is correct
67 Correct 77 ms 12084 KB Output is correct
68 Correct 85 ms 12144 KB Output is correct
69 Correct 83 ms 12276 KB Output is correct
70 Correct 86 ms 12148 KB Output is correct
71 Correct 5 ms 4992 KB Output is correct
72 Correct 7 ms 5248 KB Output is correct
73 Correct 7 ms 5248 KB Output is correct
74 Correct 7 ms 5248 KB Output is correct
75 Correct 7 ms 5248 KB Output is correct
76 Correct 7 ms 5248 KB Output is correct
77 Correct 7 ms 5248 KB Output is correct
78 Correct 7 ms 5248 KB Output is correct
79 Correct 7 ms 5376 KB Output is correct
80 Correct 93 ms 12152 KB Output is correct
81 Correct 75 ms 12144 KB Output is correct
82 Correct 81 ms 12020 KB Output is correct
83 Correct 84 ms 12088 KB Output is correct
84 Correct 6 ms 5248 KB Output is correct
85 Correct 6 ms 5248 KB Output is correct
86 Correct 7 ms 5248 KB Output is correct
87 Correct 8 ms 5248 KB Output is correct
88 Correct 7 ms 5248 KB Output is correct
89 Correct 7 ms 5316 KB Output is correct
90 Correct 6 ms 5248 KB Output is correct
91 Correct 7 ms 5248 KB Output is correct
92 Correct 7 ms 5248 KB Output is correct
93 Correct 7 ms 5248 KB Output is correct
94 Correct 5 ms 5120 KB Output is correct
95 Correct 5 ms 4992 KB Output is correct
96 Correct 5 ms 4992 KB Output is correct
97 Correct 5 ms 5120 KB Output is correct
98 Correct 5 ms 4992 KB Output is correct
99 Correct 5 ms 4992 KB Output is correct
100 Correct 6 ms 4992 KB Output is correct
101 Correct 6 ms 5120 KB Output is correct
102 Correct 6 ms 4992 KB Output is correct
103 Correct 6 ms 5120 KB Output is correct
104 Correct 11 ms 5888 KB Output is correct
105 Correct 18 ms 7424 KB Output is correct
106 Correct 6 ms 5120 KB Output is correct
107 Correct 32 ms 8824 KB Output is correct
108 Correct 38 ms 10112 KB Output is correct
109 Correct 5 ms 5120 KB Output is correct
110 Correct 54 ms 11736 KB Output is correct
111 Correct 70 ms 13308 KB Output is correct
112 Correct 5 ms 5148 KB Output is correct
113 Correct 102 ms 16116 KB Output is correct
114 Correct 47 ms 11128 KB Output is correct
115 Correct 54 ms 11156 KB Output is correct
116 Correct 39 ms 11128 KB Output is correct
117 Correct 39 ms 11256 KB Output is correct
118 Correct 49 ms 11076 KB Output is correct
119 Correct 53 ms 11764 KB Output is correct
120 Correct 45 ms 11508 KB Output is correct
121 Correct 47 ms 11124 KB Output is correct
122 Correct 53 ms 11000 KB Output is correct
123 Correct 42 ms 11384 KB Output is correct
124 Correct 5 ms 4992 KB Output is correct
125 Correct 17 ms 10236 KB Output is correct
126 Correct 18 ms 10240 KB Output is correct
127 Correct 17 ms 10240 KB Output is correct
128 Correct 16 ms 10112 KB Output is correct
129 Correct 46 ms 10112 KB Output is correct
130 Correct 17 ms 9728 KB Output is correct
131 Correct 17 ms 10240 KB Output is correct
132 Correct 16 ms 10112 KB Output is correct
133 Incorrect 6 ms 4992 KB Output isn't correct
134 Halted 0 ms 0 KB -