結果
| 問題 | No.2638 Initial fare |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 21:44:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 110 ms / 2,000 ms |
| コード長 | 1,236 bytes |
| 記録 | |
| コンパイル時間 | 2,351 ms |
| コンパイル使用メモリ | 218,904 KB |
| 最終ジャッジ日時 | 2025-02-19 16:48:27 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; ++i) {
int x,y; cin >> x >> y;
x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
vector<vector<ll>> d(4, vector<ll>(n));
for (int i = 0; i < n; ++i) {
d[0][i] = 1;
d[1][i] = g[i].size();
}
for (int i = 0; i < n; ++i) {
for (int j : g[i]) {
d[2][i] += d[1][j] - d[0][i];
}
}
for (int i = 0; i < n; ++i) {
for (int j : g[i]) {
d[3][i] += d[2][j] - d[1][i] + 1;
}
}
ll res = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j < 4; ++j) {
res += d[j][i];
}
}
cout << res/2 << endl;
}