Submission #492040

# Submission time Handle Problem Language Result Execution time Memory
492040 2021-12-05T10:45:54 Z StoRovinato Dreaming (IOI13_dreaming) C++17
47 / 100
118 ms 23092 KB
#include <bits/stdc++.h>
#include "dreaming.h"

#define MAXN 100000

using namespace std;

typedef long long ll;

vector<pair<ll, ll>> nodi[MAXN];
vector<bool> proc;
vector<ll> dist;

void dfs(ll v, vector<ll>& gruppo)
{
	proc[v] = true;
	gruppo.push_back(v);

	for (auto [u, w]: nodi[v])
	{
		if (!proc[u])
		{
			dist[u] = dist[v] + w;
			dfs(u, gruppo);
		}
	}
}

void dfs2(ll v)
{
	proc[v] = true;

	for (auto [u, w]: nodi[v])
	{
		if (!proc[u])
		{
			dist[u] = dist[v] + w;
			dfs2(u);
		}
	}
}

bool dfs3(ll v, ll p, ll y, vector<ll>& diam)
{
	if (v == y)
		return true;

	bool ok = false;
	for (auto [u, w]: nodi[v])
	{
		if (u != p)
		{
			if (dfs3(u, v, y, diam))
			{
				ok = true;
				diam.push_back(w);
				break;
			}
		}
	}
	
	return ok;
}

vector<ll> trova_diametro(ll v)
{
	vector<ll> gruppo;
	dist[v] = 0; 
	dfs(v, gruppo);


	sort(gruppo.begin(), gruppo.end(), [&](ll a, ll b){return dist[a] > dist[b];});

	for (ll i: gruppo)
		proc[i] = false;

	ll x, y;
	x = gruppo[0];

	dist[x] = 0;
	dfs2(x);

	sort(gruppo.begin(), gruppo.end(), [&](ll a, ll b){return dist[a] > dist[b];});

	y = gruppo[0];

	vector<ll> diam;
	dfs3(x, -1, y, diam);
	return diam;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
	for (ll i = 0; i < M; i++)
	{
		nodi[A[i]].push_back({B[i], T[i]});
		nodi[B[i]].push_back({A[i], T[i]});
	}

	vector<ll> valori;
	vector<ll> diam;

	dist.resize(N, 0);
	proc.resize(N, false);
	for (ll i = 0; i < N; i++)
	{
		if (!proc[i])
		{
			vector<ll> diametro = trova_diametro(i);

			/*
			cout << "\n\n";
			for (ll i: diametro)
				cout << i << " ";
			cout << "\n\n";
			*/


			if (diametro.empty())
			{
				valori.push_back(0);
				diam.push_back(0);
				continue;
			}

			ll sx = 0, dx = 0;
			for (ll j: diametro)
				dx += j;
			ll minimo = dx;
			diam.push_back(dx);
			for (ll j = 0; j < diametro.size(); j++)
			{
				sx += diametro[j];
				dx -= diametro[j];

				minimo = min(minimo, max(sx, dx));
			}

			valori.push_back(minimo);
		}
	}

	sort(valori.begin(), valori.end());
	sort(diam.begin(), diam.end());

	return max(diam.back(), valori.back() + valori[valori.size() - 2] + L);

	if (valori.size() == 1)
		return diam[0];
	if (valori.size() == 2)
		return max(diam[1], valori[0] + valori[1] + L);
	if (valori.size() > 2)
		return max(max(diam.back(), valori.back() + valori[valori.size() - 2] + L), valori[valori.size() - 2] + valori[valori.size() - 3] + 2 * L);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:131:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |    for (ll j = 0; j < diametro.size(); j++)
      |                   ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 61 ms 20920 KB Output is correct
2 Correct 65 ms 20816 KB Output is correct
3 Correct 44 ms 14336 KB Output is correct
4 Correct 9 ms 5276 KB Output is correct
5 Correct 7 ms 4044 KB Output is correct
6 Correct 14 ms 6856 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 29 ms 8732 KB Output is correct
9 Correct 39 ms 11652 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 68 ms 13940 KB Output is correct
12 Correct 103 ms 18000 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
9 Correct 2 ms 2732 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 1 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 1 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 1 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 1 ms 2636 KB Output is correct
24 Correct 1 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 20920 KB Output is correct
2 Correct 65 ms 20816 KB Output is correct
3 Correct 44 ms 14336 KB Output is correct
4 Correct 9 ms 5276 KB Output is correct
5 Correct 7 ms 4044 KB Output is correct
6 Correct 14 ms 6856 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 29 ms 8732 KB Output is correct
9 Correct 39 ms 11652 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 68 ms 13940 KB Output is correct
12 Correct 103 ms 18000 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 1 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 1 ms 2636 KB Output is correct
21 Correct 1 ms 2636 KB Output is correct
22 Correct 2 ms 2732 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 1 ms 2636 KB Output is correct
25 Correct 1 ms 2636 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
27 Correct 1 ms 2636 KB Output is correct
28 Correct 1 ms 2636 KB Output is correct
29 Correct 1 ms 2636 KB Output is correct
30 Correct 1 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 1 ms 2636 KB Output is correct
33 Correct 1 ms 2636 KB Output is correct
34 Correct 2 ms 2636 KB Output is correct
35 Correct 2 ms 2656 KB Output is correct
36 Correct 1 ms 2636 KB Output is correct
37 Correct 1 ms 2636 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 81 ms 20928 KB Output is correct
40 Correct 70 ms 20808 KB Output is correct
41 Correct 49 ms 14292 KB Output is correct
42 Correct 8 ms 5324 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 1 ms 2636 KB Output is correct
45 Correct 1 ms 2636 KB Output is correct
46 Correct 1 ms 2636 KB Output is correct
47 Correct 1 ms 2636 KB Output is correct
48 Correct 1 ms 2636 KB Output is correct
49 Correct 2 ms 2636 KB Output is correct
50 Correct 2 ms 2636 KB Output is correct
51 Correct 2 ms 2636 KB Output is correct
52 Correct 2 ms 2636 KB Output is correct
53 Correct 2 ms 2636 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2636 KB Output is correct
56 Correct 2 ms 2636 KB Output is correct
57 Correct 89 ms 11636 KB Output is correct
58 Correct 75 ms 11268 KB Output is correct
59 Correct 79 ms 11304 KB Output is correct
60 Correct 88 ms 11188 KB Output is correct
61 Correct 82 ms 11084 KB Output is correct
62 Correct 80 ms 11156 KB Output is correct
63 Correct 68 ms 10808 KB Output is correct
64 Correct 64 ms 10824 KB Output is correct
65 Correct 76 ms 10848 KB Output is correct
66 Correct 79 ms 10876 KB Output is correct
67 Correct 79 ms 11336 KB Output is correct
68 Correct 79 ms 11368 KB Output is correct
69 Correct 78 ms 11260 KB Output is correct
70 Correct 82 ms 11044 KB Output is correct
71 Correct 1 ms 2636 KB Output is correct
72 Correct 3 ms 2892 KB Output is correct
73 Correct 3 ms 2892 KB Output is correct
74 Correct 3 ms 2892 KB Output is correct
75 Correct 3 ms 2892 KB Output is correct
76 Correct 3 ms 2892 KB Output is correct
77 Correct 3 ms 2892 KB Output is correct
78 Correct 3 ms 2892 KB Output is correct
79 Correct 3 ms 2892 KB Output is correct
80 Correct 93 ms 11416 KB Output is correct
81 Correct 83 ms 11324 KB Output is correct
82 Correct 106 ms 11168 KB Output is correct
83 Correct 86 ms 11104 KB Output is correct
84 Correct 2 ms 2764 KB Output is correct
85 Correct 2 ms 2764 KB Output is correct
86 Correct 3 ms 2764 KB Output is correct
87 Correct 3 ms 2764 KB Output is correct
88 Correct 2 ms 2764 KB Output is correct
89 Correct 3 ms 2764 KB Output is correct
90 Correct 2 ms 2764 KB Output is correct
91 Correct 3 ms 2892 KB Output is correct
92 Correct 3 ms 2780 KB Output is correct
93 Correct 2 ms 2764 KB Output is correct
94 Correct 2 ms 2636 KB Output is correct
95 Correct 2 ms 2636 KB Output is correct
96 Correct 2 ms 2636 KB Output is correct
97 Correct 1 ms 2636 KB Output is correct
98 Correct 2 ms 2636 KB Output is correct
99 Correct 2 ms 2636 KB Output is correct
100 Correct 1 ms 2636 KB Output is correct
101 Correct 2 ms 2636 KB Output is correct
102 Correct 1 ms 2636 KB Output is correct
103 Correct 1 ms 2636 KB Output is correct
104 Correct 7 ms 4132 KB Output is correct
105 Correct 20 ms 6856 KB Output is correct
106 Correct 2 ms 2648 KB Output is correct
107 Correct 29 ms 8776 KB Output is correct
108 Correct 49 ms 11700 KB Output is correct
109 Correct 1 ms 2764 KB Output is correct
110 Correct 61 ms 13992 KB Output is correct
111 Correct 93 ms 18048 KB Output is correct
112 Correct 2 ms 2764 KB Output is correct
113 Correct 118 ms 23092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 6788 KB Output is correct
2 Incorrect 26 ms 6824 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
9 Correct 2 ms 2732 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 1 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 1 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 1 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 1 ms 2636 KB Output is correct
24 Correct 1 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
27 Correct 2 ms 2764 KB Output is correct
28 Correct 2 ms 2764 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 2 ms 2764 KB Output is correct
31 Correct 3 ms 2764 KB Output is correct
32 Incorrect 3 ms 2636 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 20920 KB Output is correct
2 Correct 65 ms 20816 KB Output is correct
3 Correct 44 ms 14336 KB Output is correct
4 Correct 9 ms 5276 KB Output is correct
5 Correct 7 ms 4044 KB Output is correct
6 Correct 14 ms 6856 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 29 ms 8732 KB Output is correct
9 Correct 39 ms 11652 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 68 ms 13940 KB Output is correct
12 Correct 103 ms 18000 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 1 ms 2636 KB Output is correct
17 Correct 1 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 1 ms 2636 KB Output is correct
21 Correct 1 ms 2636 KB Output is correct
22 Correct 2 ms 2732 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 1 ms 2636 KB Output is correct
25 Correct 1 ms 2636 KB Output is correct
26 Correct 2 ms 2636 KB Output is correct
27 Correct 1 ms 2636 KB Output is correct
28 Correct 1 ms 2636 KB Output is correct
29 Correct 1 ms 2636 KB Output is correct
30 Correct 1 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 1 ms 2636 KB Output is correct
33 Correct 1 ms 2636 KB Output is correct
34 Correct 2 ms 2636 KB Output is correct
35 Correct 2 ms 2656 KB Output is correct
36 Correct 1 ms 2636 KB Output is correct
37 Correct 1 ms 2636 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 81 ms 20928 KB Output is correct
40 Correct 70 ms 20808 KB Output is correct
41 Correct 49 ms 14292 KB Output is correct
42 Correct 8 ms 5324 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 1 ms 2636 KB Output is correct
45 Correct 1 ms 2636 KB Output is correct
46 Correct 1 ms 2636 KB Output is correct
47 Correct 1 ms 2636 KB Output is correct
48 Correct 1 ms 2636 KB Output is correct
49 Correct 2 ms 2636 KB Output is correct
50 Correct 2 ms 2636 KB Output is correct
51 Correct 2 ms 2636 KB Output is correct
52 Correct 2 ms 2636 KB Output is correct
53 Correct 2 ms 2636 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2636 KB Output is correct
56 Correct 2 ms 2636 KB Output is correct
57 Correct 89 ms 11636 KB Output is correct
58 Correct 75 ms 11268 KB Output is correct
59 Correct 79 ms 11304 KB Output is correct
60 Correct 88 ms 11188 KB Output is correct
61 Correct 82 ms 11084 KB Output is correct
62 Correct 80 ms 11156 KB Output is correct
63 Correct 68 ms 10808 KB Output is correct
64 Correct 64 ms 10824 KB Output is correct
65 Correct 76 ms 10848 KB Output is correct
66 Correct 79 ms 10876 KB Output is correct
67 Correct 79 ms 11336 KB Output is correct
68 Correct 79 ms 11368 KB Output is correct
69 Correct 78 ms 11260 KB Output is correct
70 Correct 82 ms 11044 KB Output is correct
71 Correct 1 ms 2636 KB Output is correct
72 Correct 3 ms 2892 KB Output is correct
73 Correct 3 ms 2892 KB Output is correct
74 Correct 3 ms 2892 KB Output is correct
75 Correct 3 ms 2892 KB Output is correct
76 Correct 3 ms 2892 KB Output is correct
77 Correct 3 ms 2892 KB Output is correct
78 Correct 3 ms 2892 KB Output is correct
79 Correct 3 ms 2892 KB Output is correct
80 Correct 93 ms 11416 KB Output is correct
81 Correct 83 ms 11324 KB Output is correct
82 Correct 106 ms 11168 KB Output is correct
83 Correct 86 ms 11104 KB Output is correct
84 Correct 2 ms 2764 KB Output is correct
85 Correct 2 ms 2764 KB Output is correct
86 Correct 3 ms 2764 KB Output is correct
87 Correct 3 ms 2764 KB Output is correct
88 Correct 2 ms 2764 KB Output is correct
89 Correct 3 ms 2764 KB Output is correct
90 Correct 2 ms 2764 KB Output is correct
91 Correct 3 ms 2892 KB Output is correct
92 Correct 3 ms 2780 KB Output is correct
93 Correct 2 ms 2764 KB Output is correct
94 Correct 2 ms 2636 KB Output is correct
95 Correct 2 ms 2636 KB Output is correct
96 Correct 2 ms 2636 KB Output is correct
97 Correct 1 ms 2636 KB Output is correct
98 Correct 2 ms 2636 KB Output is correct
99 Correct 2 ms 2636 KB Output is correct
100 Correct 1 ms 2636 KB Output is correct
101 Correct 2 ms 2636 KB Output is correct
102 Correct 1 ms 2636 KB Output is correct
103 Correct 1 ms 2636 KB Output is correct
104 Correct 7 ms 4132 KB Output is correct
105 Correct 20 ms 6856 KB Output is correct
106 Correct 2 ms 2648 KB Output is correct
107 Correct 29 ms 8776 KB Output is correct
108 Correct 49 ms 11700 KB Output is correct
109 Correct 1 ms 2764 KB Output is correct
110 Correct 61 ms 13992 KB Output is correct
111 Correct 93 ms 18048 KB Output is correct
112 Correct 2 ms 2764 KB Output is correct
113 Correct 118 ms 23092 KB Output is correct
114 Correct 30 ms 6788 KB Output is correct
115 Incorrect 26 ms 6824 KB Output isn't correct
116 Halted 0 ms 0 KB -