Submission #47057

# Submission time Handle Problem Language Result Execution time Memory
47057 2018-04-27T04:46:29 Z wzy Dreaming (IOI13_dreaming) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
vector<pii> adj[100005];
long long f[100005];
bool vis[100005];
int n , m , l;
long long ans = 0  , maxxi  , optz ; 
int a = 0 , b = 0;

void solve(int x , int y , long long d){
	if(d >= maxxi){
		a = x , maxxi = d;
	}
	for(int j = 0 ; j < adj[x].size() ; j++){
		pii v = adj[x][j];
		if(v.F == y) continue;
		solve(v.F , x , d + v.S);
	}
}

void dp(int x , int y , long long d){
	if(f[x] == -1){
		f[x] = d;
	}
	else{
		optz = min(optz , max(f[x] , d));
	}
	for(int j = 0;  j < adj[x].size() ; j++){
		pii v = adj[x][j];
		if(v.F == y) continue;
		dp(v.F , x , d + v.S);
	}
}

void mark(int x , int y){
	vis[x] = true;
	for(int j = 0 ; j < adj[x].size() ; j++){
		if(adj[x][j].F == y) continue;
		mark(adj[x][j].F,  x);
	}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
	n = N , m = M , l = L;
	for(int i = 0 ; i < m ; i++){
		adj[A[i]].pb(pii(B[i],T[i]));
		adj[B[i]].pb(pii(A[i],T[i]));
	}
	for(int i = 0 ; i < n; i ++){
		f[i] = -1;
	}
	vector<long long> opt;
	for(int i = 0 ; i< n; i ++){
		if(!vis[i]){
			a = - 1 , b = - 1 , maxxi = 0;
			solve(i , i , 0);
			maxxi = 0;
			b = a;
			solve(a , a , 0);
			ans = max(ans , maxxi);
			optz = (long long) 1e18;
			dp(a , a , 0);
			dp(b , b , 0);
		//	cout<<a<<" "<<b<<" "<<maxxi<<" "<<optz<<endl;
			opt.push_back(optz);
			mark(a , a);
		}
	}
	sort(opt.begin()  , opt.end());
	if(opt.size() >= 2){
		ans = max(ans , opt[opt.size() - 1] + l + opt[opt.size() - 2]);
	}
	if(opt.size() >= 3){
		ans = max(ans , 2*l + opt[opt.size() - 2] + opt[opt.size() - 3]);
	}
	return ans;
}


/* 
13 9 2
8 12 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3
*/

Compilation message

dreaming.cpp: In function 'void solve(int, int, long long int)':
dreaming.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0 ; j < adj[x].size() ; j++){
                  ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dp(int, int, long long int)':
dreaming.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0;  j < adj[x].size() ; j++){
                  ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void mark(int, int)':
dreaming.cpp:41:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0 ; j < adj[x].size() ; j++){
                  ~~^~~~~~~~~~~~~~~
/tmp/cc1WhqkM.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status