#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <map> 
#include <math.h>
#include <string>
#include <string.h>
#include <stdlib.h>
using namespace std;
 
int N;
vector<pair<intint>> graph[10010];
int visited[10010];
int Max;
 
void BFS(int start)
{
    queue<int> q;
    q.push(start);
    visited[start] = 0;
    
    while(!q.empty())
    {
        start = q.front();
        q.pop();
        
        for(int i = 0; i < graph[start].size(); i++)
        {
            if(visited[graph[start][i].first] == -1)
            {
                visited[graph[start][i].first] = visited[start] + graph[start][i].second;
                q.push(graph[start][i].first);    
                
                if(Max < visited[graph[start][i].first])
                {
                    Max = visited[graph[start][i].first];
                }
            }
        }    
    }
}
 
int main(void)
{
//    freopen("B1967_input.txt", "r", stdin);
    
    cin >> N;
    
    int from, to, weight;
    while(cin >> from >> to >> weight)
    {
        graph[from].push_back({to, weight});
        graph[to].push_back({from, weight});
    }
    
    for(int i = 1; i <= N; i++)
    {
        memset(visited, -1sizeof(visited));
        BFS(i);
    }
    
    cout << Max;
    
    return 0;
}
cs

+ Recent posts