結果
問題 | No.1103 Directed Length Sum |
ユーザー | tonegawa |
提出日時 | 2020-08-17 16:10:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,595 bytes |
コンパイル時間 | 1,252 ms |
コンパイル使用メモリ | 122,256 KB |
実行使用メモリ | 167,552 KB |
最終ジャッジ日時 | 2024-04-19 18:54:48 |
合計ジャッジ時間 | 9,493 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
50,176 KB |
testcase_01 | AC | 20 ms
50,176 KB |
testcase_02 | WA | - |
testcase_03 | AC | 247 ms
97,024 KB |
testcase_04 | AC | 488 ms
75,648 KB |
testcase_05 | AC | 957 ms
94,080 KB |
testcase_06 | AC | 278 ms
66,904 KB |
testcase_07 | AC | 59 ms
54,144 KB |
testcase_08 | AC | 83 ms
56,272 KB |
testcase_09 | AC | 46 ms
52,740 KB |
testcase_10 | AC | 113 ms
58,496 KB |
testcase_11 | AC | 570 ms
77,952 KB |
testcase_12 | AC | 285 ms
66,904 KB |
testcase_13 | AC | 121 ms
58,880 KB |
testcase_14 | AC | 40 ms
52,092 KB |
testcase_15 | AC | 200 ms
63,104 KB |
testcase_16 | AC | 635 ms
81,408 KB |
testcase_17 | AC | 672 ms
82,688 KB |
testcase_18 | AC | 116 ms
58,500 KB |
testcase_19 | AC | 550 ms
78,592 KB |
testcase_20 | AC | 50 ms
53,120 KB |
testcase_21 | AC | 80 ms
55,552 KB |
testcase_22 | AC | 427 ms
73,584 KB |
testcase_23 | AC | 222 ms
64,256 KB |
ソースコード
#include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <algorithm> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #define vll vector<ll> #define vvvl vector<vvl> #define vvl vector<vector<ll>> #define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c)) #define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c<b;c++) #define rep(a,b,c) for(ll a=b;a<c;a++) #define all(obj) (obj).begin(), (obj).end() typedef long long int ll; typedef long double ld; using namespace std; void get(vll &a){re(i,a.size()) scanf("%lld",&a[i]);} void get(vvl &a){re(i,a.size()) re(j,a[0].size()) scanf("%lld",&a[i][j]);} void print(vll &a){re(i,a.size()) cout<<a[i]<<(i==a.size()-1?"\n":" ");} void print(vvl &a){re(i,a.size()) re(j,a[0].size())cout<<a[i][j]<<(j==a[0].size()-1?"\n":" ");} vvl G = VV(1000001, 0, 0, ll); vll dist(1000001, 0); vll c(1000001, 0); vll ans(1000001, 0); void f(ll now, ll from){ for(auto to:G[now]){ if(to==from) continue; f(to, now); ans[now] += dist[to] + c[to]; dist[now] += dist[to] + c[to]; c[now] += c[to]; } c[now]++; } int main(int argc, char const *argv[]) { ll n;std::cin >> n; vll use(n+1, 0); re(i, n-1){ ll a, b;scanf("%lld %lld", &a, &b); G[a].push_back(b); G[b].push_back(a); use[b] = 1; } ll root = -1; for(int i=1;i<=n;i++) { if(!use[i]) { root = i; break; } } f(root, -1); ll s = 0; for(int i=1;i<=n;i++) s += ans[i]; std::cout << s << '\n'; }