Submission #578645

# Submission time Handle Problem Language Result Execution time Memory
578645 2022-06-17T12:37:14 Z 1ne Dreaming (IOI13_dreaming) C++14
0 / 100
55 ms 15572 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    int ans = 0;
    vector<vector<pair<int,int>>>adj(N);
    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]});
	 }
	 vector<pair<int,int>>node;
	 vector<bool>visited(N,false);
	 vector<int>pos;
	 vector<pair<int,int>>parent(N,{-1,-1});
	 for (int i = 0;i<N;++i){
		if (!visited[i]){
			int cur = i;
			int maxxy = 0;
			function<void(int,int,int)> dfs = [&](int u,int par,int score){
				visited[u] = true;
				if (score > maxxy){
					maxxy = score;
					cur = u;
				}
				for (auto x:adj[u]){
					if (x.first == par)continue;
					dfs(x.first,u,score + x.second);
				}
			};
			dfs(i,-1,0);

			int cur2 = cur,maxxy2 = 0;
			function<void(int,int)> dfs2 = [&](int u,int score){
				visited[u] = true;
				if (score > maxxy2){
					maxxy2 = score;
					cur2 = u;
				}
				for (auto x:adj[u]){
					if (x.first == parent[u].first)continue;
					parent[x.first] = {u,x.second};
					dfs2(x.first,score + x.second);
				}
			};
			dfs2(cur,0);
			ans = max(maxxy2,ans);
			node.push_back({maxxy2,cur2});
		}
	 }
	 for (auto x:node){
			int maxxy2 = x.first;
			int cur2 = x.second;
			int maxxy = maxxy2;
			int minny = maxxy;
			node.push_back({maxxy2,cur2});
			while(parent[cur2].first!=-1){
				maxxy-=parent[cur2].second;
				cur2 = parent[cur2].first;
				minny = min(minny,max(maxxy,maxxy2 - maxxy));
			}
			pos.push_back(minny);
	 }
	 sort(pos.begin(),pos.end());
	 if (pos.size() > 1){
		ans = max(ans,pos[pos.size() - 1] + pos[pos.size() - 2] + L);
	 }
	 if (pos.size() == 2)ans = max(ans,pos[0]);
	 return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 52 ms 15572 KB Output is correct
2 Correct 55 ms 15572 KB Output is correct
3 Correct 36 ms 10260 KB Output is correct
4 Correct 6 ms 2516 KB Output is correct
5 Correct 5 ms 1508 KB Output is correct
6 Correct 11 ms 3668 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 15572 KB Output is correct
2 Correct 55 ms 15572 KB Output is correct
3 Correct 36 ms 10260 KB Output is correct
4 Correct 6 ms 2516 KB Output is correct
5 Correct 5 ms 1508 KB Output is correct
6 Correct 11 ms 3668 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 12336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 15572 KB Output is correct
2 Correct 55 ms 15572 KB Output is correct
3 Correct 36 ms 10260 KB Output is correct
4 Correct 6 ms 2516 KB Output is correct
5 Correct 5 ms 1508 KB Output is correct
6 Correct 11 ms 3668 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Halted 0 ms 0 KB -