Submission #225928

# Submission time Handle Problem Language Result Execution time Memory
225928 2020-04-22T03:38:30 Z frodakcin Dreaming (IOI13_dreaming) C++11
32 / 100
82 ms 17784 KB
#include "dreaming.h"

#include <vector>
#include <algorithm>
#include <functional>

struct E
{
public:
	int n, w;
	bool operator < (E o) const {return w < o.w || !(o.w < w) && n < o.n;}
};
const int ML = 1e4 + 10;

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	if(N == 1) return 0;
	std::vector<std::vector<E> > a(N, std::vector<E>(0));
	std::vector<bool> vis(N, 0);
	for(int i = 0;i < M;++i)
		a[A[i]].push_back({B[i], T[i]}), a[B[i]].push_back({A[i], T[i]});
	std::function<E(int, int)> dfs = [&](int n, int p) -> E
	{
		vis[n] = 1;
		E ret = {n, 0};
		for(E x : a[n])
			if(x.n != p)
			{
				E cmp = dfs(x.n, n);
				cmp.w += x.w;
				if(ret < cmp)
					ret = cmp;
			}
		return ret;
	};
	std::function<int(int, int, int, int*)> get_dia = [&](int n, int p, int d, int *m) -> int
	{
		int md = 0;
		for(E x : a[n])
			if(x.n != p)
				md = std::max(md, x.w + get_dia(x.n, n, d+x.w, m));
		*m = std::min(*m, std::max(md, d));
		return md;
	};
	std::vector<int> lis(0);
	int ldia = 0;
	for(int i = 0;i < N;++i)
		if(!vis[i])
		{
			E t = dfs(i, -1);
			int val = N*ML;
			int dia = get_dia(t.n, -1, 0, &val);
			lis.push_back(val);
			ldia = std::max(ldia, dia);
		}
	std::sort(lis.begin(), lis.end(), std::greater<int>());
	if(lis.size() == 1)
		return ldia;
	else if(lis.size() == 2)
		return std::max(ldia, lis[0]+lis[1]+L);
	else
		return std::max({ldia, lis[0]+lis[1]+L, lis[1]+lis[2]+2*L});
}

Compilation message

dreaming.cpp: In member function 'bool E::operator<(E) const':
dreaming.cpp:11:60: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  bool operator < (E o) const {return w < o.w || !(o.w < w) && n < o.n;}
                                                 ~~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17784 KB Output is correct
3 Correct 43 ms 11768 KB Output is correct
4 Correct 14 ms 2816 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4096 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 30 ms 6008 KB Output is correct
9 Correct 39 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 58 ms 10872 KB Output is correct
12 Correct 82 ms 14456 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17784 KB Output is correct
3 Correct 43 ms 11768 KB Output is correct
4 Correct 14 ms 2816 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4096 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 30 ms 6008 KB Output is correct
9 Correct 39 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 58 ms 10872 KB Output is correct
12 Correct 82 ms 14456 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Incorrect 5 ms 256 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17784 KB Output is correct
3 Correct 43 ms 11768 KB Output is correct
4 Correct 14 ms 2816 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4096 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 30 ms 6008 KB Output is correct
9 Correct 39 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 58 ms 10872 KB Output is correct
12 Correct 82 ms 14456 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Incorrect 5 ms 256 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5248 KB Output is correct
2 Correct 28 ms 5248 KB Output is correct
3 Correct 28 ms 5248 KB Output is correct
4 Correct 30 ms 5248 KB Output is correct
5 Correct 29 ms 5400 KB Output is correct
6 Correct 31 ms 5776 KB Output is correct
7 Correct 29 ms 5504 KB Output is correct
8 Correct 27 ms 5116 KB Output is correct
9 Correct 31 ms 5248 KB Output is correct
10 Correct 28 ms 5376 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 9 ms 3320 KB Output is correct
13 Correct 9 ms 3324 KB Output is correct
14 Correct 9 ms 3324 KB Output is correct
15 Correct 9 ms 3452 KB Output is correct
16 Correct 9 ms 3452 KB Output is correct
17 Correct 9 ms 3324 KB Output is correct
18 Correct 9 ms 3324 KB Output is correct
19 Correct 9 ms 3324 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 256 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 9 ms 3324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17784 KB Output is correct
3 Correct 43 ms 11768 KB Output is correct
4 Correct 14 ms 2816 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4096 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 30 ms 6008 KB Output is correct
9 Correct 39 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 58 ms 10872 KB Output is correct
12 Correct 82 ms 14456 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 6 ms 512 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 4 ms 256 KB Output is correct
25 Correct 4 ms 256 KB Output is correct
26 Incorrect 4 ms 384 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17784 KB Output is correct
3 Correct 43 ms 11768 KB Output is correct
4 Correct 14 ms 2816 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4096 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 30 ms 6008 KB Output is correct
9 Correct 39 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 58 ms 10872 KB Output is correct
12 Correct 82 ms 14456 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Incorrect 5 ms 256 KB Output isn't correct
17 Halted 0 ms 0 KB -