43252023-03-24 15:42:20horvathabelLogisztikai központcpp17Time limit exceeded 31/501.1s10976 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/04ms7876 KiB
2Time limit exceeded0/01.1s7484 KiB
3Accepted4/44ms8292 KiB
4Accepted4/44ms8236 KiB
5Accepted4/44ms8244 KiB
6Accepted4/44ms8792 KiB
7Accepted4/46ms9028 KiB
8Accepted5/539ms9284 KiB
9Time limit exceeded0/21.036s9300 KiB
10Time limit exceeded0/21.062s9436 KiB
11Accepted2/213ms9828 KiB
12Accepted2/275ms9776 KiB
13Accepted2/2908ms9920 KiB
14Time limit exceeded0/21.034s6240 KiB
15Time limit exceeded0/21.072s9556 KiB
16Time limit exceeded0/21.06s9484 KiB
17Time limit exceeded0/21.08s9904 KiB
18Time limit exceeded0/21.004s9116 KiB
19Time limit exceeded0/21.06s10976 KiB
20Time limit exceeded0/31.075s10124 KiB