Submission #285614

# Submission time Handle Problem Language Result Execution time Memory
285614 2020-08-29T10:26:49 Z AMO5 Dreaming (IOI13_dreaming) C++17
0 / 100
1000 ms 14220 KB
#include <stdio.h>
#include <stdlib.h>
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define MAX_N 100005

using ii = pair<int,int>;

vector<ii>adj[MAX_N];
vector<bool>vis(MAX_N);
int dist[MAX_N][2];
vector<int>nodes;

void dfs(int u, int p, int d, bool bit){
	nodes.eb(u);
	dist[u][bit]=d;
	for(ii x:adj[u]){
		int v=x.fi;
		int t=x.se;
		if(v==p)continue;
		dfs(v,u,d+t,bit);
	}
	return;
}

int travelTime(int n, int m, int k, int a[], int b[], int t[]) {
	for(int i=0; i<m; i++){
		adj[a[i]].eb(b[i],t[i]);
		adj[b[i]].eb(a[i],t[i]);
	}
	int ans = 0;
	vector<int>answer;
	for(int i=0; i<n; i++){
		if(vis[i])continue;
		nodes=vector<int>();
		dfs(i,-1,0,0);
		int u=i; //farthestleaf
		for(int x:nodes){
			if(dist[x][0]>dist[u][0])u=x;
		}
		nodes=vector<int>();
		dfs(u,-1,0,0);
		int v=u; //farthest leaf
		for(int x:nodes){
			if(dist[x][0]>dist[v][0])v=x;
		}
		nodes=vector<int>();
		dfs(v,-1,0,1);
		//current max
		ans = max(ans,dist[u][1]);
		//current min
		int res = 1e9;
		for(int x:nodes){
			res = min(res,max(dist[x][0],dist[x][1]));
		}
		answer.eb(res);
	}
	sort(all(answer),greater<int>());
	if(sz(answer)>=2)ans = max(ans,answer[0]+answer[1]+k);
	if(sz(answer)>=3)ans = max(ans,answer[1]+answer[2]+2*k);
	return ans;
}
/*
int main() {
	int N, M, L, i,res;
	res = scanf("%d%d%d", &N, &M, &L);
	cerr<<N<<" "<<M<<" "<<L<<" checking \n";
	for (i = 0; i < M; i++)
		res = scanf("%d%d%d", &A[i], &B[i], &T[i]);

	int answer = travelTime(N, M, L, A, B, T);
	printf("%d\n", answer);
	return 0;
}
*/ 
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 14220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 14220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 14220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 6520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 14220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 14220 KB Time limit exceeded
2 Halted 0 ms 0 KB -