結果
| 問題 |
No.898 tri-βutree
|
| コンテスト | |
| ユーザー |
season1618
|
| 提出日時 | 2019-10-04 23:10:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,108 bytes |
| コンパイル時間 | 1,589 ms |
| コンパイル使用メモリ | 187,564 KB |
| 実行使用メモリ | 51,404 KB |
| 最終ジャッジ日時 | 2024-10-03 08:38:00 |
| 合計ジャッジ時間 | 12,667 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 1 |
| other | TLE * 1 -- * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
vector<int> g[size];
map<int,map<int,long>> len;
int par[size];int depth[size]={};
void dfs(int p,int v){
for(int u:g[v]){
if(u==p) continue;
par[u]=v;depth[u]=depth[v]+1;
dfs(v,u);
}return;
}
int main(){
int N;cin>>N;
int a,b,w;
rep(i,0,N-1){
cin>>a>>b>>w;
g[a].push_back(b);
g[b].push_back(a);
len[a][b]=w;
len[b][a]=w;
}
par[0]=-1;dfs(-1,0);
int Q;cin>>Q;
vector<pair<int,int>> x(3);//print(par,N);
long sum;
rep(i,0,Q){
cin>>x[0].second>>x[1].second>>x[2].second;
rep(i,0,3) x[i].first=-depth[x[i].second];
sort(x.begin(),x.end());
int count[N]={};
sum=0;
rep(j,0,3){
int v=x[j].second;
while(v!=0){
if(count[v]>0) break;
count[v]++;
sum+=len[v][par[v]];
v=par[v];
}
}cout<<sum<<endl;
}
}
season1618