Submission #225916

# Submission time Handle Problem Language Result Execution time Memory
225916 2020-04-22T03:03:31 Z frodakcin Dreaming (IOI13_dreaming) C++11
0 / 100
63 ms 17788 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;}
};

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 = 1;i <= N;++i)
		if(!vis[i])
		{
			E t = dfs(i, -1);
			int val = N*L;
			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});
	return 42;
}

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 61 ms 17788 KB Output is correct
2 Correct 63 ms 17656 KB Output is correct
3 Correct 44 ms 11768 KB Output is correct
4 Correct 12 ms 2944 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4224 KB Output is correct
7 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 17788 KB Output is correct
2 Correct 63 ms 17656 KB Output is correct
3 Correct 44 ms 11768 KB Output is correct
4 Correct 12 ms 2944 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4224 KB Output is correct
7 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 17788 KB Output is correct
2 Correct 63 ms 17656 KB Output is correct
3 Correct 44 ms 11768 KB Output is correct
4 Correct 12 ms 2944 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4224 KB Output is correct
7 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 5240 KB Output is correct
2 Correct 27 ms 5248 KB Output is correct
3 Correct 28 ms 5376 KB Output is correct
4 Correct 27 ms 5248 KB Output is correct
5 Correct 27 ms 5248 KB Output is correct
6 Correct 29 ms 5752 KB Output is correct
7 Correct 28 ms 5504 KB Output is correct
8 Correct 30 ms 5120 KB Output is correct
9 Correct 27 ms 5248 KB Output is correct
10 Correct 29 ms 5376 KB Output is correct
11 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 17788 KB Output is correct
2 Correct 63 ms 17656 KB Output is correct
3 Correct 44 ms 11768 KB Output is correct
4 Correct 12 ms 2944 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4224 KB Output is correct
7 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 17788 KB Output is correct
2 Correct 63 ms 17656 KB Output is correct
3 Correct 44 ms 11768 KB Output is correct
4 Correct 12 ms 2944 KB Output is correct
5 Correct 10 ms 1664 KB Output is correct
6 Correct 18 ms 4224 KB Output is correct
7 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -