Submission #338124

# Submission time Handle Problem Language Result Execution time Memory
338124 2020-12-22T14:20:21 Z nandonathaniel Dreaming (IOI13_dreaming) C++14
0 / 100
1000 ms 15340 KB
#include "dreaming.h"
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
const int MAXN=100005;

vector<pii> adj[MAXN];
vector<int> kel[MAXN];
int par[MAXN];

int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}

void join(int a,int b){
	par[find(a)]=find(b);
}

int jarak;

void dfs(int now,int par,int dist){
	if(dist>jarak)jarak=dist;
	for(auto nxt : adj[now]){
		if(nxt.first==par)continue;
		dfs(nxt.first,now,dist+nxt.second);
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for(int i=0;i<N;i++)par[i]=i;
	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]});
		join(A[i],B[i]);
	}
	for(int i=0;i<N;i++)kel[find(i)].push_back(i);
	vector<int> v;
	int ans=0;
	for(int i=0;i<N;i++){
		//for every tree, find root s.t the distance between the root and the furthest leaf is minimum
		if(kel[i].empty())continue;
		jarak=0;
		dfs(kel[i][0],-1,0);
		int root=kel[i][0],furthest=jarak,diameter=jarak;
		for(int j=1;j<kel[i].size();j++){
			jarak=0;
			dfs(kel[i][j],-1,0);
			if(jarak<furthest){
				furthest=jarak;
				root=kel[i][j];
			}
			if(jarak>diameter){
				diameter=jarak;
			}
		}
		v.push_back(furthest);
		ans=max(ans,diameter);
	}
	if(v.size()==2)ans=max(ans,v[0]+v[1]+L);
	return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int j=1;j<kel[i].size();j++){
      |               ~^~~~~~~~~~~~~~
dreaming.cpp:45:7: warning: variable 'root' set but not used [-Wunused-but-set-variable]
   45 |   int root=kel[i][0],furthest=jarak,diameter=jarak;
      |       ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 15340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 15340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 15340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 10476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 15340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 15340 KB Time limit exceeded
2 Halted 0 ms 0 KB -