43272023-03-24 15:44:06horvathabelLogisztikai központcpp17Time limit exceeded 31/501.072s9736 KiB
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> g[100001];
int bfs(int x){
	vector<bool> seen;
	seen.resize(1000001, false);
	queue<int> q; 
	q.push(x);
	int mxtav=0; 
	int tav[100001];
	seen[x]=true;
	tav[x]=0;
	while (!q.empty()){
		int v=q.front();

		q.pop();
		seen[v]=true; 
		for (auto edge:g[v]){
			if (!seen[edge.first]){
				tav[edge.first]=tav[v]+edge.second;
				q.push(edge.first);
				mxtav=max(tav[edge.first], mxtav);
			}
		}
	}
	return mxtav; 

}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for (int i=1; i<n;i++){
		int x,y,c;
		cin>>x>>y>>c;
		g[x].push_back({y,c});
		g[y].push_back({x,c});
	}
	vector<int> mego;
	int ans=INT_MAX;
	for (int i=1; i<=n;i++){
		int v=bfs(i);
		if (v<ans){
			ans=v;
			mego.clear(); 
	}
		if (v==ans) mego.push_back(i);
	}
	cout<<ans<<endl<<mego.size()<<endl;
	for (int x:mego) cout<<x<<" ";

}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/04ms7744 KiB
2Time limit exceeded0/01.065s7404 KiB
3Accepted4/44ms8144 KiB
4Accepted4/44ms8456 KiB
5Accepted4/44ms8276 KiB
6Accepted4/44ms8608 KiB
7Accepted4/46ms8748 KiB
8Accepted5/539ms8724 KiB
9Time limit exceeded0/21.072s8552 KiB
10Time limit exceeded0/21.052s8568 KiB
11Accepted2/213ms8752 KiB
12Accepted2/274ms8780 KiB
13Accepted2/2910ms8772 KiB
14Time limit exceeded0/21.052s5388 KiB
15Time limit exceeded0/21.07s8332 KiB
16Time limit exceeded0/21.072s8232 KiB
17Time limit exceeded0/21.036s8808 KiB
18Time limit exceeded0/21.052s8244 KiB
19Time limit exceeded0/21.057s9736 KiB
20Time limit exceeded0/31.057s8684 KiB