답안 #283009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
283009 2020-08-25T08:34:12 Z peijar 꿈 (IOI13_dreaming) C++17
0 / 100
67 ms 12664 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);
	vector<int> distances;
	for (auto [v, c] : G[u])
		if (!seen[v])
		{
			diam = max(diam, getDiams(v));
			distances.push_back(c + deepestPath[v]);
		}
	sort(distances.rbegin(), distances.rend());
	if (SZ(distances) > 1)
		diam = max(diam, distances[0] + distances[1]);
	else if (SZ(distances))
		diam = max(diam, distances[0]);
	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});
}

/*int main()
{
	int A[] = {0, 1, 3, 4, 5};
	int B[] = {1, 2, 4, 5, 6};
	int T[] = {1, 1, 1, 1, 1};
	cout << travelTime(6, 5, 1, A, B, T) << endl;
}*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 6016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -