45532023-03-29 16:32:29horvathabelLogisztikai központcpp17Wrong answer 6/50172ms127620 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

vector<pair<int,int>> g[1000001];
bool seen[1000001];
bool seen2[1000001];
pair<ll,ll>  mxtav[1000001];
ll mxtavvissza[1000001];
pair<ll,ll>  mxtav2[1000001];
int cnt[1000001];
priority_queue<int> q[1000001];
int dfs(int x, int tv){
		seen[x]=true;
		if (cnt[x]==1 && x!=1) return tv; 
		for (pair<int, int> edge:g[x]){
			if (!seen[edge.first]){
				int v=dfs(edge.first, edge.second); 
				if (v>mxtav[x].first){
					mxtav2[x]=mxtav[x];
					mxtav[x].first=v;
					mxtav[x].second=edge.first; 
				}
				else if (mxtav2[x].first<v){
					mxtav[x].first=v;
					mxtav[x].second=edge.first; 
				}
				seen[edge.first]=true;
		}
		}
		
	return (mxtav[x].first+tv);
}
void dfs2(int x){
	seen2[x]=true;
	for (pair<int, int> edge:g[x]){
		if (!seen2[edge.first]){
			seen2[edge.first]=true; 
			mxtavvissza[edge.first]=max(mxtavvissza[x]+edge.second,mxtavvissza[edge.first]);
			if (edge.first!=mxtav[x].second) mxtavvissza[edge.first]=max(mxtavvissza[edge.first], mxtav[x].first+edge.second);
			else  mxtavvissza[edge.first]=max(mxtavvissza[edge.first], mxtav2[x].first+edge.second);
			dfs2(edge.first);
		}

	}
}
int main() {
	int n;
	cin>>n;
	for (int i=0; i<n-1;i++){
		int x,y,c;
		cin>>x>>y>>c;
		g[x].push_back({y,c});
		g[y].push_back({x,c});
		cnt[x]++;
		cnt[y]++; 
		}
		

	dfs(1,0);
	dfs2(1);
	for (int i=1; i<=n ;i++) mxtav[i].first=max(mxtav[i].first, mxtavvissza[i]);
	vector<int> ans; 
	int z=INT_MAX; 
	for (int i=1; i<=n;i++){
		if (z>mxtav[i].first){
			z=mxtav[i].first;
			ans.clear();
		}
		if (z==mxtav[i].first) ans.push_back(i);
		
	}
	cout<<z<<endl<<ans.size()<<endl;
	for (int i:ans) cout<<i<<" ";
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/052ms111304 KiB
2Wrong answer0/0160ms126312 KiB
3Accepted4/452ms111716 KiB
4Wrong answer0/452ms112096 KiB
5Wrong answer0/443ms112396 KiB
6Wrong answer0/452ms112364 KiB
7Wrong answer0/443ms112620 KiB
8Wrong answer0/552ms112912 KiB
9Runtime error0/2172ms127620 KiB
10Runtime error0/2153ms127392 KiB
11Wrong answer0/241ms113028 KiB
12Accepted2/254ms113496 KiB
13Wrong answer0/257ms114280 KiB
14Wrong answer0/254ms114876 KiB
15Runtime error0/2165ms126928 KiB
16Runtime error0/2144ms126692 KiB
17Runtime error0/2150ms126604 KiB
18Wrong answer0/2152ms125464 KiB
19Runtime error0/2166ms126560 KiB
20Runtime error0/3143ms126580 KiB