Submission #399042

# Submission time Handle Problem Language Result Execution time Memory
399042 2021-05-05T07:21:07 Z prvocislo Dreaming (IOI13_dreaming) C++17
47 / 100
92 ms 23060 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include"dreaming.h"
typedef long long ll;
using namespace std;

const int maxn = 1e5 + 79, inf = 1e9 + 79;
vector<int> vis(maxn, 0), dp(maxn, 0);
vector<vector<pair<int, int> > > g(maxn);
void dfs1(int u, int p)
{
	vis[u] = 1;
	for (int i = 0; i < g[u].size(); i++) if (g[u][i].first == p) { g[u].erase(g[u].begin() + i); break; }
	for (pair<int, int> i : g[u])
	{
		dfs1(i.first, u);
		dp[u] = max(dp[u], dp[i.first] + i.second);
	}
}
void dfs2(int u, int dist, int &mini, int &dia)
{
	mini = min(mini, max(dist, dp[u]));
	vector<int> pf(g[u].size() + 1, 0), sf(g[u].size() + 1, 0);
	pair<int, int> p(0, 0);
	for (int i = 0; i < g[u].size(); i++)
	{
		int di = dp[g[u][i].first] + g[u][i].second; pf[i + 1] = max(pf[i], di);
		if (di > p.first) swap(p.first, p.second), p.first = di;
		else if (di > p.second) p.second = di;
	} 
	dia = max({ dia, p.first + p.second, dp[u] + dist });
	for (int i = g[u].size() - 1; i >= 0; i--)
		sf[i] = max(sf[i + 1], dp[g[u][i].first] + g[u][i].second);
	for (int i = 0; i < g[u].size(); i++)
		dfs2(g[u][i].first, max({ dist, pf[i], sf[i + 1] }) + g[u][i].second, mini, dia);
}
int travelTime(int n, int m, int l, int a[], int b[], int t[])
{
	for (int i = 0; i < m; i++)
		g[a[i]].push_back({ b[i], t[i] }), g[b[i]].push_back({ a[i], t[i] });
	vector<int> v; int ans = 0;
	for (int i = 0; i < n; i++)
		if (!vis[i])
		{
			v.push_back(inf);
			dfs1(i, -1), dfs2(i, 0, v.back(), ans);
		}
	sort(v.begin(), v.end(), greater<int>());
	ans = max(ans, v[0] + l + v[1]);
	if (v.size() > 2) ans = max(ans, v[1] + 2 * l + v[2]);
	return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs1(int, int)':
dreaming.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int i = 0; i < g[u].size(); i++) if (g[u][i].first == p) { g[u].erase(g[u].begin() + i); break; }
      |                  ~~^~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int, int&, int&)':
dreaming.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < g[u].size(); i++)
      |                  ~~^~~~~~~~~~~~~
dreaming.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (int i = 0; i < g[u].size(); i++)
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 59 ms 15224 KB Output is correct
2 Correct 60 ms 14544 KB Output is correct
3 Correct 45 ms 14016 KB Output is correct
4 Correct 10 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 15 ms 5940 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 34 ms 8176 KB Output is correct
9 Correct 39 ms 11620 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 59 ms 11588 KB Output is correct
12 Correct 64 ms 13380 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 3 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 2 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 15224 KB Output is correct
2 Correct 60 ms 14544 KB Output is correct
3 Correct 45 ms 14016 KB Output is correct
4 Correct 10 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 15 ms 5940 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 34 ms 8176 KB Output is correct
9 Correct 39 ms 11620 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 59 ms 11588 KB Output is correct
12 Correct 64 ms 13380 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 2 ms 3408 KB Output is correct
20 Correct 2 ms 3404 KB Output is correct
21 Correct 3 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 2 ms 3404 KB Output is correct
27 Correct 2 ms 3404 KB Output is correct
28 Correct 2 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 2 ms 3404 KB Output is correct
31 Correct 2 ms 3404 KB Output is correct
32 Correct 2 ms 3404 KB Output is correct
33 Correct 2 ms 3404 KB Output is correct
34 Correct 2 ms 3404 KB Output is correct
35 Correct 2 ms 3404 KB Output is correct
36 Correct 2 ms 3404 KB Output is correct
37 Correct 2 ms 3404 KB Output is correct
38 Correct 2 ms 3404 KB Output is correct
39 Correct 61 ms 15244 KB Output is correct
40 Correct 64 ms 14656 KB Output is correct
41 Correct 43 ms 13920 KB Output is correct
42 Correct 10 ms 5072 KB Output is correct
43 Correct 3 ms 3452 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3404 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 3404 KB Output is correct
50 Correct 2 ms 3404 KB Output is correct
51 Correct 2 ms 3404 KB Output is correct
52 Correct 2 ms 3404 KB Output is correct
53 Correct 2 ms 3404 KB Output is correct
54 Correct 2 ms 3404 KB Output is correct
55 Correct 2 ms 3404 KB Output is correct
56 Correct 2 ms 3404 KB Output is correct
57 Correct 70 ms 8516 KB Output is correct
58 Correct 71 ms 8516 KB Output is correct
59 Correct 67 ms 8476 KB Output is correct
60 Correct 69 ms 8524 KB Output is correct
61 Correct 68 ms 8388 KB Output is correct
62 Correct 68 ms 8388 KB Output is correct
63 Correct 66 ms 8196 KB Output is correct
64 Correct 69 ms 8260 KB Output is correct
65 Correct 66 ms 8260 KB Output is correct
66 Correct 67 ms 8280 KB Output is correct
67 Correct 71 ms 8496 KB Output is correct
68 Correct 68 ms 8516 KB Output is correct
69 Correct 72 ms 8516 KB Output is correct
70 Correct 74 ms 8428 KB Output is correct
71 Correct 3 ms 3404 KB Output is correct
72 Correct 4 ms 3536 KB Output is correct
73 Correct 4 ms 3532 KB Output is correct
74 Correct 4 ms 3532 KB Output is correct
75 Correct 5 ms 3532 KB Output is correct
76 Correct 4 ms 3532 KB Output is correct
77 Correct 4 ms 3532 KB Output is correct
78 Correct 4 ms 3532 KB Output is correct
79 Correct 4 ms 3532 KB Output is correct
80 Correct 70 ms 8496 KB Output is correct
81 Correct 76 ms 8416 KB Output is correct
82 Correct 67 ms 8388 KB Output is correct
83 Correct 73 ms 8388 KB Output is correct
84 Correct 3 ms 3532 KB Output is correct
85 Correct 3 ms 3532 KB Output is correct
86 Correct 4 ms 3532 KB Output is correct
87 Correct 4 ms 3532 KB Output is correct
88 Correct 4 ms 3532 KB Output is correct
89 Correct 4 ms 3532 KB Output is correct
90 Correct 4 ms 3532 KB Output is correct
91 Correct 4 ms 3532 KB Output is correct
92 Correct 4 ms 3532 KB Output is correct
93 Correct 3 ms 3532 KB Output is correct
94 Correct 2 ms 3404 KB Output is correct
95 Correct 3 ms 3404 KB Output is correct
96 Correct 3 ms 3404 KB Output is correct
97 Correct 3 ms 3404 KB Output is correct
98 Correct 2 ms 3404 KB Output is correct
99 Correct 2 ms 3404 KB Output is correct
100 Correct 2 ms 3404 KB Output is correct
101 Correct 2 ms 3408 KB Output is correct
102 Correct 2 ms 3404 KB Output is correct
103 Correct 2 ms 3404 KB Output is correct
104 Correct 8 ms 4300 KB Output is correct
105 Correct 15 ms 5964 KB Output is correct
106 Correct 3 ms 3404 KB Output is correct
107 Correct 28 ms 8136 KB Output is correct
108 Correct 38 ms 11568 KB Output is correct
109 Correct 3 ms 3532 KB Output is correct
110 Correct 54 ms 11552 KB Output is correct
111 Correct 63 ms 13364 KB Output is correct
112 Correct 3 ms 3532 KB Output is correct
113 Correct 92 ms 23060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 6096 KB Output is correct
2 Correct 26 ms 6516 KB Output is correct
3 Correct 27 ms 6448 KB Output is correct
4 Correct 28 ms 6492 KB Output is correct
5 Correct 29 ms 6476 KB Output is correct
6 Correct 30 ms 6964 KB Output is correct
7 Correct 28 ms 6608 KB Output is correct
8 Correct 27 ms 6524 KB Output is correct
9 Correct 27 ms 6476 KB Output is correct
10 Correct 28 ms 6628 KB Output is correct
11 Correct 2 ms 3460 KB Output is correct
12 Correct 9 ms 4040 KB Output is correct
13 Correct 9 ms 4040 KB Output is correct
14 Correct 9 ms 4040 KB Output is correct
15 Correct 9 ms 4044 KB Output is correct
16 Correct 9 ms 4040 KB Output is correct
17 Correct 9 ms 4040 KB Output is correct
18 Correct 9 ms 4040 KB Output is correct
19 Correct 11 ms 4040 KB Output is correct
20 Incorrect 2 ms 3404 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 3 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 2 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 2 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 3 ms 3532 KB Output is correct
28 Correct 3 ms 3532 KB Output is correct
29 Correct 3 ms 3404 KB Output is correct
30 Correct 3 ms 3532 KB Output is correct
31 Correct 4 ms 3592 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 4 ms 3532 KB Output is correct
34 Correct 4 ms 3532 KB Output is correct
35 Correct 2 ms 3404 KB Output is correct
36 Correct 2 ms 3404 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 2 ms 3444 KB Output is correct
39 Correct 2 ms 3452 KB Output is correct
40 Correct 3 ms 3404 KB Output is correct
41 Correct 2 ms 3404 KB Output is correct
42 Correct 2 ms 3456 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3448 KB Output is correct
48 Correct 2 ms 3448 KB Output is correct
49 Correct 2 ms 3460 KB Output is correct
50 Correct 3 ms 3404 KB Output is correct
51 Correct 3 ms 3404 KB Output is correct
52 Incorrect 2 ms 3404 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 15224 KB Output is correct
2 Correct 60 ms 14544 KB Output is correct
3 Correct 45 ms 14016 KB Output is correct
4 Correct 10 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 15 ms 5940 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 34 ms 8176 KB Output is correct
9 Correct 39 ms 11620 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 59 ms 11588 KB Output is correct
12 Correct 64 ms 13380 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 2 ms 3408 KB Output is correct
20 Correct 2 ms 3404 KB Output is correct
21 Correct 3 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 2 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 2 ms 3404 KB Output is correct
26 Correct 2 ms 3404 KB Output is correct
27 Correct 2 ms 3404 KB Output is correct
28 Correct 2 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 2 ms 3404 KB Output is correct
31 Correct 2 ms 3404 KB Output is correct
32 Correct 2 ms 3404 KB Output is correct
33 Correct 2 ms 3404 KB Output is correct
34 Correct 2 ms 3404 KB Output is correct
35 Correct 2 ms 3404 KB Output is correct
36 Correct 2 ms 3404 KB Output is correct
37 Correct 2 ms 3404 KB Output is correct
38 Correct 2 ms 3404 KB Output is correct
39 Correct 61 ms 15244 KB Output is correct
40 Correct 64 ms 14656 KB Output is correct
41 Correct 43 ms 13920 KB Output is correct
42 Correct 10 ms 5072 KB Output is correct
43 Correct 3 ms 3452 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 2 ms 3404 KB Output is correct
47 Correct 2 ms 3404 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 3404 KB Output is correct
50 Correct 2 ms 3404 KB Output is correct
51 Correct 2 ms 3404 KB Output is correct
52 Correct 2 ms 3404 KB Output is correct
53 Correct 2 ms 3404 KB Output is correct
54 Correct 2 ms 3404 KB Output is correct
55 Correct 2 ms 3404 KB Output is correct
56 Correct 2 ms 3404 KB Output is correct
57 Correct 70 ms 8516 KB Output is correct
58 Correct 71 ms 8516 KB Output is correct
59 Correct 67 ms 8476 KB Output is correct
60 Correct 69 ms 8524 KB Output is correct
61 Correct 68 ms 8388 KB Output is correct
62 Correct 68 ms 8388 KB Output is correct
63 Correct 66 ms 8196 KB Output is correct
64 Correct 69 ms 8260 KB Output is correct
65 Correct 66 ms 8260 KB Output is correct
66 Correct 67 ms 8280 KB Output is correct
67 Correct 71 ms 8496 KB Output is correct
68 Correct 68 ms 8516 KB Output is correct
69 Correct 72 ms 8516 KB Output is correct
70 Correct 74 ms 8428 KB Output is correct
71 Correct 3 ms 3404 KB Output is correct
72 Correct 4 ms 3536 KB Output is correct
73 Correct 4 ms 3532 KB Output is correct
74 Correct 4 ms 3532 KB Output is correct
75 Correct 5 ms 3532 KB Output is correct
76 Correct 4 ms 3532 KB Output is correct
77 Correct 4 ms 3532 KB Output is correct
78 Correct 4 ms 3532 KB Output is correct
79 Correct 4 ms 3532 KB Output is correct
80 Correct 70 ms 8496 KB Output is correct
81 Correct 76 ms 8416 KB Output is correct
82 Correct 67 ms 8388 KB Output is correct
83 Correct 73 ms 8388 KB Output is correct
84 Correct 3 ms 3532 KB Output is correct
85 Correct 3 ms 3532 KB Output is correct
86 Correct 4 ms 3532 KB Output is correct
87 Correct 4 ms 3532 KB Output is correct
88 Correct 4 ms 3532 KB Output is correct
89 Correct 4 ms 3532 KB Output is correct
90 Correct 4 ms 3532 KB Output is correct
91 Correct 4 ms 3532 KB Output is correct
92 Correct 4 ms 3532 KB Output is correct
93 Correct 3 ms 3532 KB Output is correct
94 Correct 2 ms 3404 KB Output is correct
95 Correct 3 ms 3404 KB Output is correct
96 Correct 3 ms 3404 KB Output is correct
97 Correct 3 ms 3404 KB Output is correct
98 Correct 2 ms 3404 KB Output is correct
99 Correct 2 ms 3404 KB Output is correct
100 Correct 2 ms 3404 KB Output is correct
101 Correct 2 ms 3408 KB Output is correct
102 Correct 2 ms 3404 KB Output is correct
103 Correct 2 ms 3404 KB Output is correct
104 Correct 8 ms 4300 KB Output is correct
105 Correct 15 ms 5964 KB Output is correct
106 Correct 3 ms 3404 KB Output is correct
107 Correct 28 ms 8136 KB Output is correct
108 Correct 38 ms 11568 KB Output is correct
109 Correct 3 ms 3532 KB Output is correct
110 Correct 54 ms 11552 KB Output is correct
111 Correct 63 ms 13364 KB Output is correct
112 Correct 3 ms 3532 KB Output is correct
113 Correct 92 ms 23060 KB Output is correct
114 Correct 26 ms 6096 KB Output is correct
115 Correct 26 ms 6516 KB Output is correct
116 Correct 27 ms 6448 KB Output is correct
117 Correct 28 ms 6492 KB Output is correct
118 Correct 29 ms 6476 KB Output is correct
119 Correct 30 ms 6964 KB Output is correct
120 Correct 28 ms 6608 KB Output is correct
121 Correct 27 ms 6524 KB Output is correct
122 Correct 27 ms 6476 KB Output is correct
123 Correct 28 ms 6628 KB Output is correct
124 Correct 2 ms 3460 KB Output is correct
125 Correct 9 ms 4040 KB Output is correct
126 Correct 9 ms 4040 KB Output is correct
127 Correct 9 ms 4040 KB Output is correct
128 Correct 9 ms 4044 KB Output is correct
129 Correct 9 ms 4040 KB Output is correct
130 Correct 9 ms 4040 KB Output is correct
131 Correct 9 ms 4040 KB Output is correct
132 Correct 11 ms 4040 KB Output is correct
133 Incorrect 2 ms 3404 KB Output isn't correct
134 Halted 0 ms 0 KB -