結果
| 問題 |
No.3113 The farthest point
|
| コンテスト | |
| ユーザー |
タンバリン
|
| 提出日時 | 2025-04-20 13:35:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,383 bytes |
| コンパイル時間 | 1,444 ms |
| コンパイル使用メモリ | 141,896 KB |
| 実行使用メモリ | 31,640 KB |
| 最終ジャッジ日時 | 2025-04-20 13:36:05 |
| 合計ジャッジ時間 | 5,123 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 WA * 13 |
ソースコード
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include<utility>
#include<stack>
#include <iomanip>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
#define P pair<int,int>
#define Graph vector<vector<int>>
#define float long double
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repi(itr,m) for(auto itr=(m).begin();itr!=(m).end();itr++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vi vector<int>
#define int long long
const int INF=1e18;
int dx[8]={0,1,0,-1,-1,-1,1,1};
int dy[8]={1,0,-1,0,-1,1,-1,1};
#include <time.h>
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false));}
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false));}
struct point{
int x,y;
};
void yn(bool t){
if(t)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
int solve(){
clock_t start = clock();
int n;cin>>n;
vector<vector<P>>g(n+1);
rep(i,1,n){
int u,v,w;cin>>u>>v>>w;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
vector<int>dist1(n+1,-INF);
dist1[2]=0;
queue<P>pq;//to come
pq.push({2,0});
while(!pq.empty()){
auto [to,come]=pq.front();
pq.pop();
for(auto [v,cost]:g[to]){
if(v==come)continue;
dist1[v]=dist1[to]+cost;
pq.push({v,to});
}
}
priority_queue<P>cnt;
rep(i,1,n+1)cnt.push({dist1[i],i});
int ans=-INF;
while(1){
auto [cost,idx]=cnt.top();
cnt.pop();
vector<int>dist2(n+1,-INF);
dist2[idx]=0;
queue<P>pq2;//to come
pq2.push({idx,0});
while(!pq2.empty()){
auto [to,come]=pq2.front();
pq2.pop();
for(auto [v,cost]:g[to]){
if(v==come)continue;
dist2[v]=dist2[to]+cost;
pq2.push({v,to});
}
}
rep(i,1,n+1){
ans=max(ans,dist2[i]);
cnt.push({dist2[i],i});
}
clock_t end= clock();
if(end-start>1900)break;
}
cout<<ans<<endl;
assert(true);
return 0;
}
signed main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
solve();
}
タンバリン