답안 #997239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997239 2024-06-11T21:40:43 Z codefox 꿈 (IOI13_dreaming) C++14
0 / 100
34 ms 12900 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

#define pii pair<int, int>

vector<int> depth;
vector<vector<pii>> graph;
vector<int> vis;
vector<int> vis2;
vector<int> nums;

void dfs(int i, int d)
{
	if(vis[i]) return;
	vis[i] = 1;
	nums.push_back(i);
	depth[i] = d;
	for (pii ele:graph[i]) dfs(ele.first, ele.second+d);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
	depth.assign(N, 1e9);
	graph.assign(N, vector<pii>());
	vis.assign(N, 0);
	vis2.assign(N, 0);
	vector<int> ind(N, 0);
	for (int i = 0; i < M; i++)
	{
		graph[A[i]].push_back({B[i], T[i]});
		graph[B[i]].push_back({A[i], T[i]});
		ind[A[i]]++;
		ind[B[i]]++;
	}
	int sol = 0;
	vector<int> nodes;
	vector<int> md(N, 0);
	for (int i = 0; i < N; i++)
	{
		if (vis[i]) continue;
		nums.clear();
		dfs(i, 0);
		int mx = 0;
		priority_queue<pii, vector<pii>, greater<pii>> pq;
		for (int ele:nums) if (ind[ele]==1) pq.push({0, ele});
		int h = 0;
		while(pq.size())
		{
			int j, d;
			tie(d, j) = pq.top();
			pq.pop();
			mx = max(mx, d);
			if (vis2[j]) continue;
			h++;
			vis2[j] = 1;
			for (pii ele:graph[j])
			{	
				md[ele.first] = max(md[ele.first], ele.second+d);
				if (!vis[ele.first]) mx = max(mx, md[ele.first]);
				ind[ele.first]--;
				if (ind[ele.first]==1) pq.push({md[ele.first], ele.first});
			}
			//not going back
		}
		int mmx = 0;
		int emx = 0;
		for (int ele:nums) 
		{
			if (depth[ele]>mmx)
			{
				mmx = depth[ele];
				emx = ele;	
			}
			vis[ele] = 0;
		}
		nums.clear();
		dfs(emx, 0);
		for (int ele:nums) 
		{
			mmx = max(mmx, depth[ele]);
		}

		nodes.push_back(mx);
		sol = max(sol, mmx);
	}
	sort(nodes.begin(), nodes.end());
	if (nodes.size()==2) sol = max(sol, nodes[0]+nodes[1]+L);
	else if (nodes.size()>2) sol = max(sol, max(nodes[nodes.size()-2]+nodes[nodes.size()-3]+2*L, nodes[nodes.size()-2]+nodes.back()+L));
	return sol;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 12820 KB Output is correct
2 Correct 34 ms 12900 KB Output is correct
3 Correct 22 ms 8664 KB Output is correct
4 Correct 5 ms 2136 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 9 ms 3164 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 12820 KB Output is correct
2 Correct 34 ms 12900 KB Output is correct
3 Correct 22 ms 8664 KB Output is correct
4 Correct 5 ms 2136 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 9 ms 3164 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 7132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 12820 KB Output is correct
2 Correct 34 ms 12900 KB Output is correct
3 Correct 22 ms 8664 KB Output is correct
4 Correct 5 ms 2136 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 9 ms 3164 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -