45582023-03-29 17:43:38horvathabelLogisztikai központcpp17Wrong answer 0/50143ms42148 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

vector<pair<int,int>> g[100001];
bool seen[100001];
bool seen2[100001];
pair<ll,ll>  mxtav[100001];
ll mxtavvissza[100001];
pair<ll,ll>  mxtav2[100001];
int cnt[100001];
priority_queue<int> q[100001];
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]){
								seen[edge.first]=true;

				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){
					mxtav2[x].first=v;
					mxtav2[x].second=edge.first; 
				}
		}
		}
		
	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=LONG_LONG_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
base0/50
1Wrong answer0/07ms12808 KiB
2Wrong answer0/0130ms27816 KiB
3Wrong answer0/47ms13136 KiB
4Wrong answer0/47ms13196 KiB
5Wrong answer0/47ms13192 KiB
6Wrong answer0/47ms13312 KiB
7Wrong answer0/46ms13404 KiB
8Wrong answer0/57ms13756 KiB
9Wrong answer0/2135ms29984 KiB
10Wrong answer0/2143ms30220 KiB
11Wrong answer0/28ms14200 KiB
12Wrong answer0/28ms14484 KiB
13Wrong answer0/213ms15124 KiB
14Wrong answer0/218ms16260 KiB
15Wrong answer0/2128ms29532 KiB
16Wrong answer0/2126ms28680 KiB
17Wrong answer0/2138ms30212 KiB
18Wrong answer0/2104ms26588 KiB
19Wrong answer0/2142ms28752 KiB
20Wrong answer0/3142ms42148 KiB