結果
問題 | No.2638 Initial fare |
ユーザー |
|
提出日時 | 2024-02-19 21:45:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 97 ms / 2,000 ms |
コード長 | 1,091 bytes |
コンパイル時間 | 3,336 ms |
コンパイル使用メモリ | 235,972 KB |
実行使用メモリ | 24,496 KB |
最終ジャッジ日時 | 2024-09-29 01:40:54 |
合計ジャッジ時間 | 5,752 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
コンパイルメッセージ
main.cpp: In lambda function: main.cpp:30:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 30 | auto [t1, t2, t3, t4] = self(self, to, now); | ^
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using P = pair<ll, ll>;using T = tuple<ll, ll, ll, ll>;#include <atcoder/all>using namespace atcoder;// using mint = modint998244353;// using mint = modint1000000007;#define rep(i, n) for(ll i = 0; i < n; i++)#define reps(i, l, r) for(ll i = l; i < r; i++)int main() {cin.tie(nullptr);ios_base::sync_with_stdio(false);ll n; cin >> n;vector<vector<ll>> Graph(n);rep(i,n-1) {ll u, v; cin >> u >> v; u--; v--;Graph[u].push_back(v);Graph[v].push_back(u);}ll ans = 0;auto dfs = [&](auto self, ll now, ll pre) -> T {bool f = false;ll n1 = 1, n2 = 0, n3 = 0, n4 = 0;for(auto to: Graph[now]) {if(to == pre) continue;auto [t1, t2, t3, t4] = self(self, to, now);ans += n2*t1 + n3*t1 + n2*t2;n2 += t1, n3 += t2, n4 += t3;}ans += n2 + n3 + n4;return T(n1, n2, n3, n4);};T t = dfs(dfs, 0, -1);cout << ans << endl;return 0;}