Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- struct arista
- {
- int desde, hasta, costo;
- };
- vector <vector <arista> > ady;
- vector <int> dist;
- vector <bool> visit;
- void DFS(int n)
- {
- visit[n] = true;
- for(const auto &i:ady[n])
- {
- if(!visit[i.hasta])
- {
- dist[i.hasta] = dist[n]+i.costo;
- DFS(i.hasta);
- }
- }
- }
- int main()
- {
- freopen("puesto.in", "r", stdin);
- freopen("puesto.out", "w", stdout);
- int n;
- cin >> n;
- ady.resize(300001);
- for(int i=0; i<n; i++)
- {
- int a, b, c;
- cin >> a >> b >> c;
- ady[a].push_back({a, b, c});
- ady[b].push_back({b, a, c});
- }
- dist = vector <int> (300001, 0);
- visit = vector <bool> (300001, false);
- DFS(1);
- int maxNodo = 1;
- for(int i=1; i<=300000; i++)
- if(dist[i] > dist[maxNodo])
- maxNodo = i;
- dist = vector <int> (300001, 0);
- visit = vector <bool> (300001, false);
- DFS(maxNodo);
- for(int i=1; i<=300000; i++)
- if(dist[i] > dist[maxNodo])
- maxNodo = i;
- printf("%.1f\n", dist[maxNodo]/2.0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement