結果
問題 |
No.3113 The farthest point
|
ユーザー |
|
提出日時 | 2025-04-18 22:31:33 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,198 bytes |
コンパイル時間 | 3,499 ms |
コンパイル使用メモリ | 285,312 KB |
実行使用メモリ | 19,968 KB |
最終ジャッジ日時 | 2025-04-18 22:31:43 |
合計ジャッジ時間 | 8,915 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 13 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ int n;cin>>n; vector<vector<pair<int,int>>>connect(n); for(int i=0;i<n-1;i++){ int a,b,c;cin>>a>>b>>c; a--;b--; connect[a].push_back({b,c}); connect[b].push_back({a,c}); } //関数の返り値->遠い奴のコストも一緒に const int inf=1e18; auto BFS=[&](auto BFS,int start)->pair<int,int>{ vector<bool>vis(n,false); vector<int>dist(n,inf); dist[start]=0; vis[start]=true; deque<int>que; que.push_back(start); while(!que.empty()){ int now=que.front(); que.pop_front(); for(auto [to,weight]:connect[now]){ if(!vis[to]){ vis[to]=true; dist[to]=dist[now]+weight; que.push_back(to); } } } int o=0,t=0; for(int i=0;i<n;i++){ if(dist[i]>t){ t=dist[i]; o=i; } } return {o,t}; }; auto[nxt,w]=BFS(BFS,0); auto[d,ans]=BFS(BFS,nxt); cout<<ans<<endl; }