結果
問題 |
No.2638 Initial fare
|
ユーザー |
![]() |
提出日時 | 2024-02-11 16:58:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 746 bytes |
コンパイル時間 | 2,400 ms |
コンパイル使用メモリ | 202,564 KB |
最終ジャッジ日時 | 2025-02-19 05:09:48 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 RE * 19 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector ikeru(n, vector<int>(0)); for (int i=0; i<n-1; i++){ int u, v; cin >> u >> v; u--; v--; ikeru[u].push_back(v); ikeru[v].push_back(u); } long long ans = 0; vector dp(n, vector<long long>(4)); vector<int> mx(n, 0); auto dfs = [&](auto self, int i, int p) -> void { dp[i][0] = 1; mx[i] = 1; for (int j: ikeru[i]){ if (j == p) continue; self(self, j, i); for (int x=0; x<mx[i]; x++){ for (int y=0; y<mx[j]; y++){ if (x+y+1 > 3) break; ans += dp[i][x] * dp[j][y]; } } for (int x=0; x<mx[j]; x++){ dp[i][x+1] += dp[j][x]; } mx[i] = max(mx[i], mx[j]+1); } }; dfs(dfs, 0, -1); cout << ans << '\n'; }