結果
問題 | No.1103 Directed Length Sum |
ユーザー | cn_449 |
提出日時 | 2020-07-03 22:14:35 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,635 bytes |
コンパイル時間 | 1,024 ms |
コンパイル使用メモリ | 119,428 KB |
実行使用メモリ | 159,500 KB |
最終ジャッジ日時 | 2023-10-17 04:11:03 |
合計ジャッジ時間 | 7,424 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 22 ms
50,168 KB |
testcase_01 | AC | 21 ms
50,168 KB |
testcase_02 | WA | - |
testcase_03 | AC | 178 ms
54,708 KB |
testcase_04 | AC | 315 ms
59,144 KB |
testcase_05 | AC | 567 ms
65,744 KB |
testcase_06 | AC | 171 ms
55,976 KB |
testcase_07 | AC | 49 ms
51,488 KB |
testcase_08 | AC | 67 ms
52,280 KB |
testcase_09 | AC | 39 ms
50,960 KB |
testcase_10 | AC | 92 ms
53,072 KB |
testcase_11 | AC | 326 ms
59,936 KB |
testcase_12 | AC | 192 ms
55,976 KB |
testcase_13 | AC | 95 ms
53,072 KB |
testcase_14 | AC | 34 ms
50,696 KB |
testcase_15 | AC | 153 ms
54,656 KB |
testcase_16 | AC | 383 ms
61,256 KB |
testcase_17 | AC | 397 ms
61,784 KB |
testcase_18 | AC | 94 ms
53,072 KB |
testcase_19 | AC | 357 ms
60,200 KB |
testcase_20 | AC | 45 ms
51,224 KB |
testcase_21 | AC | 70 ms
52,016 KB |
testcase_22 | AC | 278 ms
58,352 KB |
testcase_23 | AC | 153 ms
54,920 KB |
ソースコード
#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<vector<int>> graph(1000010, vector<int>()); vector<ll> cnt(1000010), sz(1000010, 1), vis(1000010); void dfs(int n) { if (vis[n]) return; for (int i : graph[n]) { dfs(i); cnt[n] += cnt[i]; sz[n] += sz[i]; } cnt[n] += sz[n] - 1; vis[n] = true; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; rep(i, n - 1) { int u, v; cin >> u >> v; u--; v--; graph[u].pb(v); } rep(i, n) dfs(i); ll ans = 0; rep(i, n) ans += cnt[i]; cout << ans << '\n'; }