답안 #225917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225917 2020-04-22T03:06:18 Z frodakcin 꿈 (IOI13_dreaming) C++11
32 / 100
62 ms 17912 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 = 0;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;}
                                                 ~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17912 KB Output is correct
3 Correct 42 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 4096 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 30 ms 6136 KB Output is correct
9 Correct 43 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 56 ms 11000 KB Output is correct
12 Correct 62 ms 14328 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17912 KB Output is correct
3 Correct 42 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 4096 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 30 ms 6136 KB Output is correct
9 Correct 43 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 56 ms 11000 KB Output is correct
12 Correct 62 ms 14328 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Incorrect 4 ms 256 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17912 KB Output is correct
3 Correct 42 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 4096 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 30 ms 6136 KB Output is correct
9 Correct 43 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 56 ms 11000 KB Output is correct
12 Correct 62 ms 14328 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Incorrect 4 ms 256 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 5248 KB Output is correct
2 Correct 27 ms 5240 KB Output is correct
3 Correct 27 ms 5240 KB Output is correct
4 Correct 29 ms 5248 KB Output is correct
5 Correct 29 ms 5240 KB Output is correct
6 Correct 30 ms 5752 KB Output is correct
7 Correct 29 ms 5504 KB Output is correct
8 Correct 27 ms 5248 KB Output is correct
9 Correct 28 ms 5112 KB Output is correct
10 Correct 28 ms 5376 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 9 ms 3448 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 3324 KB Output is correct
16 Correct 9 ms 3324 KB Output is correct
17 Correct 9 ms 3324 KB Output is correct
18 Correct 10 ms 3324 KB Output is correct
19 Correct 9 ms 3324 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 4 ms 256 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 9 ms 3324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17912 KB Output is correct
3 Correct 42 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 4096 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 30 ms 6136 KB Output is correct
9 Correct 43 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 56 ms 11000 KB Output is correct
12 Correct 62 ms 14328 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 512 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 6 ms 512 KB Output is correct
22 Correct 7 ms 768 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Incorrect 4 ms 384 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 17784 KB Output is correct
2 Correct 62 ms 17912 KB Output is correct
3 Correct 42 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 4096 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 30 ms 6136 KB Output is correct
9 Correct 43 ms 8696 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 56 ms 11000 KB Output is correct
12 Correct 62 ms 14328 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Incorrect 4 ms 256 KB Output isn't correct
17 Halted 0 ms 0 KB -