結果
問題 | No.1098 LCAs |
ユーザー | cn_449 |
提出日時 | 2020-06-26 21:54:23 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,732 bytes |
コンパイル時間 | 1,099 ms |
コンパイル使用メモリ | 119,040 KB |
実行使用メモリ | 22,292 KB |
最終ジャッジ日時 | 2023-09-18 04:19:09 |
合計ジャッジ時間 | 4,721 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
9,132 KB |
testcase_01 | AC | 6 ms
9,232 KB |
testcase_02 | AC | 6 ms
9,304 KB |
testcase_03 | AC | 6 ms
9,372 KB |
testcase_04 | AC | 5 ms
9,240 KB |
testcase_05 | AC | 5 ms
9,244 KB |
testcase_06 | AC | 6 ms
9,288 KB |
testcase_07 | AC | 6 ms
9,224 KB |
testcase_08 | AC | 5 ms
9,196 KB |
testcase_09 | AC | 5 ms
9,280 KB |
testcase_10 | AC | 5 ms
9,120 KB |
testcase_11 | AC | 5 ms
9,228 KB |
testcase_12 | AC | 5 ms
9,232 KB |
testcase_13 | AC | 6 ms
9,328 KB |
testcase_14 | AC | 6 ms
9,000 KB |
testcase_15 | AC | 5 ms
9,068 KB |
testcase_16 | AC | 6 ms
9,076 KB |
testcase_17 | AC | 6 ms
9,136 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 106 ms
16,140 KB |
testcase_24 | AC | 105 ms
16,144 KB |
testcase_25 | AC | 105 ms
16,460 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } vector<int> sz(200010, 1), par(200010); vector<vector<int>> graph(200010, vector<int>()); void dfs(int n, int p) { par[n] = p; for (int i : graph[n]) { if (i == p) continue; dfs(i, n); sz[n] += sz[i]; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; rep(_, n - 1) { int u, v; cin >> u >> v; u--; v--; graph[u].pb(v); graph[v].pb(u); } dfs(0, -1); rep(i, n) { ll ans = sz[i] * 2 - 1; ll cnt = 0; for (int j : graph[i]) { if (j != par[i]) { cnt += sz[j]; ans -= sz[j] * sz[j]; } } cout << ans + cnt * cnt << '\n'; } }