Submission #96750

# Submission time Handle Problem Language Result Execution time Memory
96750 2019-02-11T17:28:59 Z figter001 Dreaming (IOI13_dreaming) C++14
0 / 100
69 ms 10232 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn = 1e5;

vector<pair<int,int>> g[maxn];
vector<int> C;
int mx,to,cst[maxn],t,best,mn,vis[maxn],c,ans;

void path(int u,int cost){
	vis[u] = c;
	if(cost > mx){
		mx = cost;
		to = u;
	}
	for(pair<int,int> cur : g[u]){
		int v = cur.first;
		int w = cur.second;
		if(vis[v] == c)continue;
		path(v,cost + w);
	}
}

void dfs(int u,int cost){
	vis[u] = c;
	if(t == 1){
		cst[u] = max(cst[u],cost);
		if(cst[u] < mn){
			mn = cst[u];
			best = u;
		}
	}else cst[u] = cost;
	for(pair<int,int> cur : g[u]){
		int v = cur.first;
		int w = cur.second;
		if(vis[v] == c)continue;
		dfs(v,cost + w);
	}	
}

void find(int s){
	mn = 2e9;
	mx = -1;
	c++;
	path(s,0);
	int a = to;
	c++;
	mx = -1;
	path(a,0);
	int b = to;
	t = 0;
	c++;
	dfs(a,0);
	t = 1;
	c++;
	dfs(b,0);
	ans = max(ans,mn);
	C.push_back(mn);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for(int i=0;i<M;i++){
		g[A[i]].push_back({B[i],T[i]});
		g[B[i]].push_back({A[i],T[i]});
	}
	for(int i=0;i<N;i++)
		if(!vis[i])
			find(i);
	sort(C.begin(),C.end());
	reverse(C.begin(),C.end());
	if(C.size() > 1){
		ans = max(ans,C[0] + C[1] + L);
		if(C.size() > 2)ans = max(ans,C[1] + C[2] + 2*L);
	}
    return mx;
}

Compilation message

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 10232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 10096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 6136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 2788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -