Submission #28858

# Submission time Handle Problem Language Result Execution time Memory
28858 2017-07-17T11:07:03 Z nibnalin Dreaming (IOI13_dreaming) C++14
47 / 100
146 ms 16500 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include "dreaming.h"
using namespace std;

const int maxn = int(1e5)+5, inf = int(1e9)+5;

int n, m, l, D[2][maxn], vis[maxn];
vector<int> cur_comp;
vector<pair<int, int>> guys, graph[maxn];

int dfs(int node, int par, int d, int type)
{
	D[type][node] = d;
	if(type) cur_comp.push_back(node);
	int cur = node;
	for(auto it: graph[node])
	{
		if(it.first != par)
		{
			int tmp = dfs(it.first, node, d+it.second, type);
			if(D[type][cur] < D[type][tmp]) cur = tmp;
		}
	}
	return cur;
}


int travelTime(int _N, int _M, int _L, int _A[], int _B[], int _T[]) {
	n = _N, m = _M, l = _L;
	for(int i = 0;i < m;i++)
	{
		graph[_A[i]].push_back({_B[i], _T[i]});
		graph[_B[i]].push_back({_A[i], _T[i]});
	}

	int res = -1;
	set<pair<int, int>, greater<pair<int, int>>> S;
	for(int i = 0;i < n;i++)
	{
		if(!vis[i])
		{
			cur_comp.clear();
			int f1 = dfs(i, -1, 0, 0);
			int f2 = dfs(f1, -1, 0, 0);
			dfs(f2, -1, 0, 1);
			pair<int, int> mini = {inf, inf};
			for(auto it: cur_comp)
			{
				mini = min(mini, {max(D[0][it], D[1][it]), it});
				vis[it] = 1;
			}
			res = max(res, D[0][f2]);
			//cout << mini.first << " " << mini.second << "\n";
			guys.push_back(mini);
			S.insert(mini);
		}
	}

	int res2 = inf;
	for(auto it: guys)
	{
		if(int(S.size()) < 2) continue;
		S.erase(it), S.insert({it.first-l, it.second});

		int tmp = l*2+((S.begin()->first)+(next(S.begin())->first));
		res2 = min(res2, tmp);

		S.insert(it), S.erase({it.first-l, it.second});
	}

	return max(res, res2);
}
# Verdict Execution time Memory Grader output
1 Correct 85 ms 15332 KB Output is correct
2 Correct 90 ms 15336 KB Output is correct
3 Correct 51 ms 10996 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 36 ms 7004 KB Output is correct
9 Correct 44 ms 8832 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 63 ms 10616 KB Output is correct
12 Correct 80 ms 12912 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 15332 KB Output is correct
2 Correct 90 ms 15336 KB Output is correct
3 Correct 51 ms 10996 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 36 ms 7004 KB Output is correct
9 Correct 44 ms 8832 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 63 ms 10616 KB Output is correct
12 Correct 80 ms 12912 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2724 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 5 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 3 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 15332 KB Output is correct
2 Correct 90 ms 15336 KB Output is correct
3 Correct 51 ms 10996 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 36 ms 7004 KB Output is correct
9 Correct 44 ms 8832 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 63 ms 10616 KB Output is correct
12 Correct 80 ms 12912 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2724 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 5 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 3 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 4 ms 2688 KB Output is correct
39 Correct 73 ms 15348 KB Output is correct
40 Correct 103 ms 15288 KB Output is correct
41 Correct 46 ms 11020 KB Output is correct
42 Correct 13 ms 4608 KB Output is correct
43 Correct 4 ms 2688 KB Output is correct
44 Correct 4 ms 2688 KB Output is correct
45 Correct 4 ms 2688 KB Output is correct
46 Correct 3 ms 2688 KB Output is correct
47 Correct 3 ms 2688 KB Output is correct
48 Correct 4 ms 2688 KB Output is correct
49 Correct 4 ms 2688 KB Output is correct
50 Correct 4 ms 2688 KB Output is correct
51 Correct 4 ms 2688 KB Output is correct
52 Correct 4 ms 2688 KB Output is correct
53 Correct 4 ms 2688 KB Output is correct
54 Correct 3 ms 2688 KB Output is correct
55 Correct 4 ms 2688 KB Output is correct
56 Correct 3 ms 2688 KB Output is correct
57 Correct 79 ms 9584 KB Output is correct
58 Correct 80 ms 9464 KB Output is correct
59 Correct 94 ms 9528 KB Output is correct
60 Correct 106 ms 9336 KB Output is correct
61 Correct 104 ms 9460 KB Output is correct
62 Correct 86 ms 9268 KB Output is correct
63 Correct 76 ms 9216 KB Output is correct
64 Correct 86 ms 9176 KB Output is correct
65 Correct 98 ms 9204 KB Output is correct
66 Correct 87 ms 9308 KB Output is correct
67 Correct 119 ms 9508 KB Output is correct
68 Correct 113 ms 9584 KB Output is correct
69 Correct 124 ms 9352 KB Output is correct
70 Correct 99 ms 9292 KB Output is correct
71 Correct 4 ms 2688 KB Output is correct
72 Correct 6 ms 2944 KB Output is correct
73 Correct 5 ms 2944 KB Output is correct
74 Correct 6 ms 2944 KB Output is correct
75 Correct 6 ms 2944 KB Output is correct
76 Correct 5 ms 2944 KB Output is correct
77 Correct 5 ms 2944 KB Output is correct
78 Correct 6 ms 2944 KB Output is correct
79 Correct 6 ms 2944 KB Output is correct
80 Correct 146 ms 9588 KB Output is correct
81 Correct 119 ms 9456 KB Output is correct
82 Correct 96 ms 9436 KB Output is correct
83 Correct 93 ms 9428 KB Output is correct
84 Correct 5 ms 2944 KB Output is correct
85 Correct 5 ms 2816 KB Output is correct
86 Correct 5 ms 2816 KB Output is correct
87 Correct 5 ms 2944 KB Output is correct
88 Correct 6 ms 2944 KB Output is correct
89 Correct 5 ms 2816 KB Output is correct
90 Correct 6 ms 2944 KB Output is correct
91 Correct 5 ms 2944 KB Output is correct
92 Correct 5 ms 2944 KB Output is correct
93 Correct 5 ms 2944 KB Output is correct
94 Correct 4 ms 2688 KB Output is correct
95 Correct 4 ms 2688 KB Output is correct
96 Correct 4 ms 2688 KB Output is correct
97 Correct 4 ms 2688 KB Output is correct
98 Correct 4 ms 2688 KB Output is correct
99 Correct 3 ms 2688 KB Output is correct
100 Correct 4 ms 2688 KB Output is correct
101 Correct 4 ms 2688 KB Output is correct
102 Correct 4 ms 2688 KB Output is correct
103 Correct 4 ms 2688 KB Output is correct
104 Correct 11 ms 3712 KB Output is correct
105 Correct 20 ms 5480 KB Output is correct
106 Correct 4 ms 2816 KB Output is correct
107 Correct 36 ms 7032 KB Output is correct
108 Correct 41 ms 8824 KB Output is correct
109 Correct 4 ms 2816 KB Output is correct
110 Correct 60 ms 10660 KB Output is correct
111 Correct 71 ms 12912 KB Output is correct
112 Correct 4 ms 2816 KB Output is correct
113 Correct 111 ms 16500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 9584 KB Output is correct
2 Correct 68 ms 9584 KB Output is correct
3 Correct 74 ms 9584 KB Output is correct
4 Correct 73 ms 9584 KB Output is correct
5 Correct 71 ms 9592 KB Output is correct
6 Correct 76 ms 10368 KB Output is correct
7 Correct 78 ms 9968 KB Output is correct
8 Correct 68 ms 9456 KB Output is correct
9 Correct 73 ms 9328 KB Output is correct
10 Correct 77 ms 9840 KB Output is correct
11 Correct 4 ms 2764 KB Output is correct
12 Correct 67 ms 9324 KB Output is correct
13 Correct 67 ms 9332 KB Output is correct
14 Correct 72 ms 9324 KB Output is correct
15 Correct 65 ms 9328 KB Output is correct
16 Correct 72 ms 9324 KB Output is correct
17 Correct 73 ms 9336 KB Output is correct
18 Correct 65 ms 9332 KB Output is correct
19 Correct 67 ms 9328 KB Output is correct
20 Incorrect 3 ms 2688 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 15332 KB Output is correct
2 Correct 90 ms 15336 KB Output is correct
3 Correct 51 ms 10996 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 36 ms 7004 KB Output is correct
9 Correct 44 ms 8832 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 63 ms 10616 KB Output is correct
12 Correct 80 ms 12912 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Correct 5 ms 2944 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 5 ms 2816 KB Output is correct
19 Correct 5 ms 2944 KB Output is correct
20 Correct 4 ms 2816 KB Output is correct
21 Correct 5 ms 2816 KB Output is correct
22 Correct 6 ms 2944 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 5 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 5 ms 2688 KB Output is correct
39 Correct 4 ms 2688 KB Output is correct
40 Incorrect 4 ms 2688 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 15332 KB Output is correct
2 Correct 90 ms 15336 KB Output is correct
3 Correct 51 ms 10996 KB Output is correct
4 Correct 12 ms 4608 KB Output is correct
5 Correct 10 ms 3712 KB Output is correct
6 Correct 18 ms 5632 KB Output is correct
7 Correct 4 ms 2816 KB Output is correct
8 Correct 36 ms 7004 KB Output is correct
9 Correct 44 ms 8832 KB Output is correct
10 Correct 4 ms 2816 KB Output is correct
11 Correct 63 ms 10616 KB Output is correct
12 Correct 80 ms 12912 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2724 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 5 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 3 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 3 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2688 KB Output is correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 4 ms 2688 KB Output is correct
39 Correct 73 ms 15348 KB Output is correct
40 Correct 103 ms 15288 KB Output is correct
41 Correct 46 ms 11020 KB Output is correct
42 Correct 13 ms 4608 KB Output is correct
43 Correct 4 ms 2688 KB Output is correct
44 Correct 4 ms 2688 KB Output is correct
45 Correct 4 ms 2688 KB Output is correct
46 Correct 3 ms 2688 KB Output is correct
47 Correct 3 ms 2688 KB Output is correct
48 Correct 4 ms 2688 KB Output is correct
49 Correct 4 ms 2688 KB Output is correct
50 Correct 4 ms 2688 KB Output is correct
51 Correct 4 ms 2688 KB Output is correct
52 Correct 4 ms 2688 KB Output is correct
53 Correct 4 ms 2688 KB Output is correct
54 Correct 3 ms 2688 KB Output is correct
55 Correct 4 ms 2688 KB Output is correct
56 Correct 3 ms 2688 KB Output is correct
57 Correct 79 ms 9584 KB Output is correct
58 Correct 80 ms 9464 KB Output is correct
59 Correct 94 ms 9528 KB Output is correct
60 Correct 106 ms 9336 KB Output is correct
61 Correct 104 ms 9460 KB Output is correct
62 Correct 86 ms 9268 KB Output is correct
63 Correct 76 ms 9216 KB Output is correct
64 Correct 86 ms 9176 KB Output is correct
65 Correct 98 ms 9204 KB Output is correct
66 Correct 87 ms 9308 KB Output is correct
67 Correct 119 ms 9508 KB Output is correct
68 Correct 113 ms 9584 KB Output is correct
69 Correct 124 ms 9352 KB Output is correct
70 Correct 99 ms 9292 KB Output is correct
71 Correct 4 ms 2688 KB Output is correct
72 Correct 6 ms 2944 KB Output is correct
73 Correct 5 ms 2944 KB Output is correct
74 Correct 6 ms 2944 KB Output is correct
75 Correct 6 ms 2944 KB Output is correct
76 Correct 5 ms 2944 KB Output is correct
77 Correct 5 ms 2944 KB Output is correct
78 Correct 6 ms 2944 KB Output is correct
79 Correct 6 ms 2944 KB Output is correct
80 Correct 146 ms 9588 KB Output is correct
81 Correct 119 ms 9456 KB Output is correct
82 Correct 96 ms 9436 KB Output is correct
83 Correct 93 ms 9428 KB Output is correct
84 Correct 5 ms 2944 KB Output is correct
85 Correct 5 ms 2816 KB Output is correct
86 Correct 5 ms 2816 KB Output is correct
87 Correct 5 ms 2944 KB Output is correct
88 Correct 6 ms 2944 KB Output is correct
89 Correct 5 ms 2816 KB Output is correct
90 Correct 6 ms 2944 KB Output is correct
91 Correct 5 ms 2944 KB Output is correct
92 Correct 5 ms 2944 KB Output is correct
93 Correct 5 ms 2944 KB Output is correct
94 Correct 4 ms 2688 KB Output is correct
95 Correct 4 ms 2688 KB Output is correct
96 Correct 4 ms 2688 KB Output is correct
97 Correct 4 ms 2688 KB Output is correct
98 Correct 4 ms 2688 KB Output is correct
99 Correct 3 ms 2688 KB Output is correct
100 Correct 4 ms 2688 KB Output is correct
101 Correct 4 ms 2688 KB Output is correct
102 Correct 4 ms 2688 KB Output is correct
103 Correct 4 ms 2688 KB Output is correct
104 Correct 11 ms 3712 KB Output is correct
105 Correct 20 ms 5480 KB Output is correct
106 Correct 4 ms 2816 KB Output is correct
107 Correct 36 ms 7032 KB Output is correct
108 Correct 41 ms 8824 KB Output is correct
109 Correct 4 ms 2816 KB Output is correct
110 Correct 60 ms 10660 KB Output is correct
111 Correct 71 ms 12912 KB Output is correct
112 Correct 4 ms 2816 KB Output is correct
113 Correct 111 ms 16500 KB Output is correct
114 Correct 67 ms 9584 KB Output is correct
115 Correct 68 ms 9584 KB Output is correct
116 Correct 74 ms 9584 KB Output is correct
117 Correct 73 ms 9584 KB Output is correct
118 Correct 71 ms 9592 KB Output is correct
119 Correct 76 ms 10368 KB Output is correct
120 Correct 78 ms 9968 KB Output is correct
121 Correct 68 ms 9456 KB Output is correct
122 Correct 73 ms 9328 KB Output is correct
123 Correct 77 ms 9840 KB Output is correct
124 Correct 4 ms 2764 KB Output is correct
125 Correct 67 ms 9324 KB Output is correct
126 Correct 67 ms 9332 KB Output is correct
127 Correct 72 ms 9324 KB Output is correct
128 Correct 65 ms 9328 KB Output is correct
129 Correct 72 ms 9324 KB Output is correct
130 Correct 73 ms 9336 KB Output is correct
131 Correct 65 ms 9332 KB Output is correct
132 Correct 67 ms 9328 KB Output is correct
133 Incorrect 3 ms 2688 KB Output isn't correct
134 Halted 0 ms 0 KB -