답안 #282990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282990 2020-08-25T08:19:34 Z peijar 꿈 (IOI13_dreaming) C++17
18 / 100
60 ms 12540 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

#define SZ(v) ((int)(v).size())
using ll = long long;

const int MAXN = 1e5;
vector<pair<int, int> > G[MAXN];
bool seen[MAXN];
int deepestPath[MAXN];
int nodeEx[MAXN];

int getDiams(int u)
{
	seen[u] = true;	
	int diam(0);
	for (auto [v, c] : G[u])
		if (!seen[v])
		{
			diam = max(diam, getDiams(v));
			deepestPath[u] = max(deepestPath[u], deepestPath[v] + c);
		}
	return diam;
}

int calcExcentricity(int u, int lenUp, int p)
{
	seen[u] = true;
	nodeEx[u] = max(lenUp,  deepestPath[u]);
	int furthestNode(-1);
	int dis(0);
	for (auto [v, c] : G[u])
		if (v != p and deepestPath[v] + c > dis)
			furthestNode = v, dis = deepestPath[v] + c;
	int totExcentricity(nodeEx[u]);
	for (auto [v, c] : G[u])
	{
		if (v == p)
			continue;
		if (v != furthestNode)
			totExcentricity = min(totExcentricity, calcExcentricity(v, max(lenUp+c, dis + c), u));
		else
		{
			int d(lenUp+c);
			for (auto [w, dd] : G[u])
				if (w != p and w != furthestNode)
					d = max(d, dd + deepestPath[w] + c);
			totExcentricity = min(totExcentricity, calcExcentricity(v, d, u));
		}
	}
	return totExcentricity;
}

int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
	for (int i(0); i < M; ++i)
	{
		G[A[i]].emplace_back(B[i], T[i]);
		G[B[i]].emplace_back(A[i], T[i]);
	}
	int ret(0);
	for (int i(0); i < N; ++i)
		if (!seen[i])
			ret = max(ret, getDiams(i));
	for (int i(0); i < N; ++i)
		seen[i] = false;
	vector<int> ex;
	for (int i(0); i < N; ++i)
		if (!seen[i])
			ex.push_back(calcExcentricity(i, 0, i));
	sort(ex.rbegin(), ex.rend());
	if (SZ(ex) == 1)
		return ret;
	if (SZ(ex) == 2)
		return max(ret, ex[0] + ex[1] + L);
	else
		return max({ret, ex[0] + ex[1] + L, ex[1] + ex[2] + 2*L});
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 12540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 12540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 12540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 6656 KB Output is correct
2 Correct 29 ms 6656 KB Output is correct
3 Correct 29 ms 6648 KB Output is correct
4 Correct 30 ms 6648 KB Output is correct
5 Correct 31 ms 6648 KB Output is correct
6 Correct 33 ms 7168 KB Output is correct
7 Correct 30 ms 6776 KB Output is correct
8 Correct 37 ms 6692 KB Output is correct
9 Correct 32 ms 6648 KB Output is correct
10 Correct 30 ms 6776 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 6 ms 4220 KB Output is correct
13 Correct 7 ms 4252 KB Output is correct
14 Correct 7 ms 4220 KB Output is correct
15 Correct 6 ms 4220 KB Output is correct
16 Correct 6 ms 4092 KB Output is correct
17 Correct 5 ms 3836 KB Output is correct
18 Correct 8 ms 4220 KB Output is correct
19 Correct 7 ms 4092 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 6 ms 4092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 12540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 12540 KB Output isn't correct
2 Halted 0 ms 0 KB -