結果

問題 No.872 All Tree Path
ユーザー ateate
提出日時 2019-11-20 13:31:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,955 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 210,696 KB
実行使用メモリ 818,048 KB
最終ジャッジ日時 2024-04-15 22:22:08
合計ジャッジ時間 6,785 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

void solve1();void solve2();
int main(){
  solve1();
  return 0;
}
using vertex = struct vertex{ll to,cost;vertex(ll to,ll cost):to(to),cost(cost){}};
using edge = struct edge{ll from,to,cost;edge(ll from,ll to,ll cost):from(from),to(to),cost(cost){}};
using weighted_adjlist = vector<vector<vertex>>;
using weighted_edge = vector<edge>;

void solve1(){

  ll n;
  cin>>n;
  weighted_adjlist adj(n);
  rep(_,n-1){
    ll u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    adj[u].emplace_back(v,w);
    adj[v].emplace_back(u,w);
  }

  auto dist = make_vector<ll>(n,n);
  rep(v,n){
    dist[v][v]=0;
    using T3 = tuple<ll,ll,ll>;
    using T4 = tuple<ll,ll,ll,ll>;
    queue<T3> que;
    que.emplace(v,-1,0);
    while(!que.empty()){
      ll now,prv,cost;
      tie(now,prv,cost)=que.front();
      que.pop();
      dist[v][now]=cost;
      for(auto nxt:adj[now]){
        if(nxt.to==prv)continue;
        que.emplace(nxt.to,now,cost+nxt.cost);
      }
    }
  }
  ll ans = 0;
  rep(i,n)rep(j,n)ans+=dist[i][j];
  cout<<(ans)<<endl;

}
0