結果
| 問題 | 
                            No.3113 The farthest point
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-04-19 14:05:30 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 935 bytes | 
| コンパイル時間 | 989 ms | 
| コンパイル使用メモリ | 77,028 KB | 
| 実行使用メモリ | 18,704 KB | 
| 最終ジャッジ日時 | 2025-04-19 14:05:35 | 
| 合計ジャッジ時間 | 4,854 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 WA * 13 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
using ll = long long;
const int MAXN = 200005;
vector<pair<int, ll>> graph[MAXN];
struct Result {
    int node;
    ll dist;
};
Result dfs(int node, int parent, ll dist) {
    Result res = {node, dist};
    for (auto [next, weight] : graph[node]) {
        if (next == parent) continue;
        Result tmp = dfs(next, node, dist + weight);
        if (tmp.dist > res.dist) {
            res = tmp;
        }
    }
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        graph[u].emplace_back(v, w);
        graph[v].emplace_back(u, w);
    }
    Result r1 = dfs(1, -1, 0);
    Result r2 = dfs(r1.node, -1, 0);
    cout << max(r2.dist, 0LL) << '\n';
    return 0;
}