結果
問題 | No.1103 Directed Length Sum |
ユーザー | tonegawa |
提出日時 | 2020-08-17 16:13:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,589 bytes |
コンパイル時間 | 1,156 ms |
コンパイル使用メモリ | 123,596 KB |
実行使用メモリ | 140,224 KB |
最終ジャッジ日時 | 2024-04-19 18:56:45 |
合計ジャッジ時間 | 10,499 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
26,752 KB |
testcase_01 | AC | 12 ms
26,752 KB |
testcase_02 | WA | - |
testcase_03 | AC | 261 ms
77,544 KB |
testcase_04 | AC | 566 ms
58,752 KB |
testcase_05 | AC | 1,012 ms
82,176 KB |
testcase_06 | AC | 335 ms
47,744 KB |
testcase_07 | AC | 56 ms
31,872 KB |
testcase_08 | AC | 88 ms
34,432 KB |
testcase_09 | AC | 40 ms
30,080 KB |
testcase_10 | AC | 138 ms
37,376 KB |
testcase_11 | AC | 612 ms
61,824 KB |
testcase_12 | AC | 342 ms
47,744 KB |
testcase_13 | AC | 155 ms
37,632 KB |
testcase_14 | AC | 31 ms
29,184 KB |
testcase_15 | AC | 249 ms
43,136 KB |
testcase_16 | AC | 701 ms
66,048 KB |
testcase_17 | AC | 711 ms
67,584 KB |
testcase_18 | AC | 140 ms
37,376 KB |
testcase_19 | AC | 609 ms
62,592 KB |
testcase_20 | AC | 44 ms
30,720 KB |
testcase_21 | AC | 84 ms
33,664 KB |
testcase_22 | AC | 509 ms
56,192 KB |
testcase_23 | AC | 300 ms
44,288 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); int dist[1000001], c[1000001], ans[1000001]; 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%1000000007 << '\n'; }