Submission #997248

# Submission time Handle Problem Language Result Execution time Memory
997248 2024-06-11T22:00:57 Z codefox Dreaming (IOI13_dreaming) C++14
0 / 100
33 ms 15064 KB
    #include <bits/stdc++.h>
    #include "dreaming.h"
     
    using namespace std;
     
    #define pii pair<int, int>
     
    vector<int> depth;
    vector<vector<pii>> graph;
    vector<int> vis;
    vector<int> vis2;
    vector<int> nums;
	vector<pii> par;
     
    void dfs(int i, int d)
    {
    	if(vis[i]) return;
    	vis[i] = 1;
    	nums.push_back(i);
    	depth[i] = d;
    	for (pii ele:graph[i]) 
	{
	if (!vis[ele.first]) par[ele.first] = {i, ele.second};
	dfs(ele.first, ele.second+d);
	}
    }
     
    int travelTime(int N, int M, int L, int A[], int B[], int T[])
    {
    	depth.assign(N, 1e9);
    	graph.assign(N, vector<pii>());
    	vis.assign(N, 0);
    	vis2.assign(N, 0);
    	vector<int> ind(N, 0);
	par.assign(N, {0, 0});
    	for (int i = 0; i < M; i++)
    	{
    		graph[A[i]].push_back({B[i], T[i]});
    		graph[B[i]].push_back({A[i], T[i]});
    		ind[A[i]]++;
    		ind[B[i]]++;
    	}
    	int sol = 0;
    	vector<int> nodes;
    	vector<int> md(N, 0);
    	for (int i = 0; i < N; i++)
    	{
    		if (vis[i]) continue;
    		nums.clear();
    		dfs(i, 0);
    		int mmx = 0;
    		int emx = 0;
    		for (int ele:nums) 
    		{
    			if (depth[ele]>mmx)
    			{
    				mmx = depth[ele];
    				emx = ele;	
    			}
    			vis[ele] = 0;
    		}
    		nums.clear();
    		dfs(emx, 0);
		int ii = emx;
    		for (int ele:nums) 
    		{
    			if (depth[ele]>mmx)
    			{
    				mmx = depth[ele];
    				emx = ele;	
    			}
    		}
		int d = 0;
		int mn = 1e9;
		while (emx != ii)
		{
			mn = min(mn, max(depth[emx], d));
			d += par[emx].second;
			emx = par[emx].first;
			mn = min(mn, max(depth[emx], d));
		}
     
    		nodes.push_back(mn);
    		sol = max(sol, mmx);
    	}
    	sort(nodes.begin(), nodes.end());
    	if (nodes.size()==2) sol = max(sol, nodes[0]+nodes[1]+L);
    	else if (nodes.size()>2) sol = max(sol, max(nodes[nodes.size()-2]+nodes[nodes.size()-3]+2*L, nodes[nodes.size()-2]+nodes.back()+L));
    	return sol;
    }
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 15064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 15064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 7900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 15064 KB Output isn't correct
2 Halted 0 ms 0 KB -