Submission #787980

# Submission time Handle Problem Language Result Execution time Memory
787980 2023-07-19T15:46:15 Z allin27x Dreaming (IOI13_dreaming) C++17
0 / 100
112 ms 44552 KB
#include <bits/stdc++.h>
using namespace std;
#include "dreaming.h"

int ds[2][(int)1e5];
unordered_map<int,int> adj[(int)1e5];
int vis[(int)1e5];
int ind = 0;
unordered_set<int> sets[(int)1e5];
int cp[(int)1e5];

void dfs(int i , int p, int len, int x){
	sets[ind].insert(i);
	vis[i] = 1;
	ds[x][i] = len;
	for (auto const &pair: adj[i]){
		int c = pair.first; int w= pair.second;
		if (c==p) continue;
		dfs(c,i, len+w,x);
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]){
	for (int i=0; i<M; i++){
		int a = A[i]; int b = B[i];
		adj[a][b] = T[i]; adj[b][a] = T[i];
	}

	for (int i=0; i<N; i++){
		if (vis[i]) continue;
		dfs(i,i,0,0);
		int a1 = i;
		for (auto c: sets[ind]){
			if (ds[0][c]>ds[0][a1]) a1 = c;
		}
		dfs(a1,a1,0,0);
		int a2 = a1;
		for (auto c: sets[ind]){
			if (ds[0][c]>ds[0][a2]) a2 = c;
		}
		dfs(a2,a2,0,1);
		int ans = 1e7;
		for (auto c: sets[ind]){
			ans = min(ans, max(ds[0][c], ds[1][c]));
		}
		cp[ind] = ans;
		ind++;
	}
	if (ind == 1){
		int s = 0;
		for (int c=0; c<N; c++){
			if (ds[0][c]>ds[0][s]) s = c;
		}
		return ds[0][s];
	}
	sort(cp, cp+ind);
	return L + cp[ind-1] + cp[ind-2];
}

// int main(){
// 	int n = 12; int m = 8 ;
// 	int l = 2;
// 	int a[] = {0, 8, 2, 5, 5, 1, 1, 10};
// 	int b[] = {8, 2, 7, 11, 1, 3, 9, 6};
// 	int t[] = {4, 2, 4, 3, 7, 1, 5, 3};
// 	cout<<travelTime(n,m,l,a,b,t);
// }
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 44552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 44552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 31996 KB Output is correct
2 Incorrect 59 ms 31960 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 44552 KB Output isn't correct
2 Halted 0 ms 0 KB -