답안 #976184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976184 2024-05-06T09:16:19 Z Amaarsaa 꿈 (IOI13_dreaming) C++14
0 / 100
35 ms 16320 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
vector < pair < int , int > > adj[100005];
vector < int > v;
vector < int > q;
int mx, mx_cnt;
int d[100004], used[100004];
void Dia(int node, int parent, int dist) {
	d[node] = dist;
	q.push_back(node);
	if ( d[node] > mx_cnt) {
		mx_cnt = d[node];
		mx = node;
	}
	v.push_back(node);
	used[node] = 1;
	for ( pair < int, int >& A : adj[node]) {
		int child = A.first;
		if ( child == parent) continue;
		Dia(child, node, dist + A.second);
	}
}
int Dfs(int node, int parent, int fn) {
	int baiga = 0;
	if ( node == fn) return 1;
	for ( pair < int, int >& A : adj[node]) {
		int child = A.first;
		if ( child == parent) continue;
		v.push_back(child);
		
		if(Dfs(child, node, fn)) {
			baiga = 1;
		}
		else {
			v.pop_back();
		}
	}
	return baiga;
}
vector < int > Ans;
void Go(int x) {
	int y;
	mx = x;
	mx_cnt = 0;
	Dia(x, x, 0);
	for ( int X : q) d[X] = 0;
	q.clear();
	x = mx;
	mx_cnt = 0;
	Dia(mx, mx, 0);
	y = mx;
	int dist = mx_cnt;
	v.clear();
	v.push_back(x);
	Dfs(x, x, y);
	int s = 1e9;
	for ( int X : v) {
		s = min(s, max(d[X], dist -d[X])); 
	}
	Ans.push_back(s);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for (int i = 0; i < M; i ++) {
		adj[A[i]].push_back({B[i], T[i]});
		adj[B[i]].push_back({A[i], T[i]});
	}
	for (int i = 0; i < N; i ++) {
		if (!used[i]) {
			Go(i);
		}
	}
	sort(Ans.rbegin(), Ans.rend());
	if ( Ans.size() == 2) return Ans[0] + Ans[1] + L;
	return max(Ans[0] + Ans[1] , Ans[1] + Ans[2] + L) + L;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 16320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 16320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6992 KB Output is correct
2 Correct 15 ms 7004 KB Output is correct
3 Correct 15 ms 7004 KB Output is correct
4 Correct 14 ms 6936 KB Output is correct
5 Correct 14 ms 7032 KB Output is correct
6 Correct 15 ms 7392 KB Output is correct
7 Correct 18 ms 7136 KB Output is correct
8 Correct 14 ms 7004 KB Output is correct
9 Correct 14 ms 7004 KB Output is correct
10 Correct 16 ms 7260 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 4 ms 5080 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 5 ms 5080 KB Output is correct
15 Correct 4 ms 5080 KB Output is correct
16 Correct 5 ms 5080 KB Output is correct
17 Correct 5 ms 5080 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 4 ms 5208 KB Output is correct
20 Incorrect 1 ms 4444 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 16320 KB Output isn't correct
2 Halted 0 ms 0 KB -