結果
問題 | No.3113 The farthest point |
ユーザー |
|
提出日時 | 2025-04-19 05:09:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,422 bytes |
コンパイル時間 | 1,400 ms |
コンパイル使用メモリ | 121,756 KB |
実行使用メモリ | 19,596 KB |
最終ジャッジ日時 | 2025-04-19 05:09:22 |
合計ジャッジ時間 | 8,149 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 13 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <set> #include <cmath> #include <iomanip> #include <stack> #include <queue> #include <bitset> #include <tuple> #include <map> #include <functional> #define fi first #define se second #define rep(i,n) for(ll i=0;i<(n);i++) #define rrep(i,n) for(ll i=(n)-1;i>=0;i--) #define orep(i,n) for(ll i=1;i<=(n);i++) #define nfor(i,s,n) for(ll i=(s);i<(n);i++) #define dfor(i,s,n) for(ll i=(s)-1;i>=n;i--) #define INF 9e18//9223372036854775807 #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) #define pb push_back #define pob pop_back #define vc vector #define YES cout << "Yes" << endl; #define NO cout << "No" << endl; #define YN {cout << "Yes" << endl;}else{cout << "No" << endl;} #define dame cout << -1 << endl; #define vc_unique(v) v.erase(unique(v.begin(), v.end()), v.end()) #define vc_rotate(v) rotate(v.begin(), v.begin()+1, v.end()) #define pop_cnt(s) ll(popcount(uint64_t(s))) #define next_p(v) next_permutation(v.begin(),v.end()) #ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif using namespace std; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using vvl = vector<vector<ll>>; using vl = vector<ll>; using Graph = vector<vector<ll>>; template<class T> using pq = priority_queue<T,vc<T>,less<T>>; template<class T> using pq_g = priority_queue<T,vc<T>,greater<T>>; vl dx = {0,1,0,-1};//vl dx = {1,1,0,-1,-1,-1,0,1}; vl dy = {1,0,-1,0};//vl dy = {0,1,1,1,0,-1,-1,-1}; bool out_grid(ll i, ll j, ll h, ll w){//trueならcontinueする return(!(0 <= i && i < h && 0 <= j && j<w)); } void print(ld x){printf("%.20Lf\n", x);} ////////////////////////////////////////////////////////////////// vl dist; vector<vector<pair<ll,ll>>> UVW; void dfs(ll v){ for(auto [nv,w] : UVW[v]){ if(dist[nv] != -INF)continue; dist[nv] = dist[v] + w; dfs(nv); } } int main(){ ll N; cin >> N; UVW.resize(N); dist.resize(N); rep(i,N-1){ ll tmp1,tmp2,tmp3; cin >> tmp1 >> tmp2 >> tmp3; UVW[tmp1-1].pb({tmp2-1,tmp3}); UVW[tmp2-1].pb({tmp1-1,tmp3}); } rep(i,N){ dist[i] = -INF; } dist[0] = 0; dfs(0); ll av = 0; rep(i,N){ if(dist[av] <= dist[i])av = i; } rep(i,N){ dist[i] = -INF; } dist[av] = 0; dfs(av); rep(i,N){ if(dist[av] <= dist[i])av = i; } cout << dist[av] <<endl; }