結果
| 問題 |
No.3113 The farthest point
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-01 21:05:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 683 bytes |
| コンパイル時間 | 2,138 ms |
| コンパイル使用メモリ | 194,952 KB |
| 実行使用メモリ | 17,408 KB |
| 最終ジャッジ日時 | 2025-05-01 21:05:42 |
| 合計ジャッジ時間 | 7,027 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d%d%d",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fLL;
const int MAX=2e5+10;
struct node{int to,w;};
vector<node> mp[MAX];
ll dp[MAX],ans;
void dfs(int x,int fa)
{
int to,w;
ll mx=0;
dp[x]=0;
for(auto &it:mp[x])
{
to=it.to;
w=it.w;
if(to==fa) continue;
dfs(to,x);
ans=max(ans,dp[to]+w);
ans=max(ans,mx+dp[to]+w);
mx=max(mx,dp[to]+w);
}
dp[x]=mx;
}
int main()
{
int n,i,a,b,c;
scanf("%d",&n);
for(i=1;i<=n;i++) mp[i].clear();
for(i=1;i<n;i++)
{
scanf("%d%d%d",&a,&b,&c);
mp[a].push_back({b,c});
mp[b].push_back({a,c});
}
ans=0;
dfs(1,0);
printf("%lld\n",ans);
return 0;
}