結果
問題 | No.1103 Directed Length Sum |
ユーザー | forest3 |
提出日時 | 2020-07-04 22:23:29 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,234 ms / 3,000 ms |
コード長 | 884 bytes |
コンパイル時間 | 3,179 ms |
コンパイル使用メモリ | 180,840 KB |
実行使用メモリ | 69,708 KB |
最終ジャッジ日時 | 2023-10-19 17:35:59 |
合計ジャッジ時間 | 15,520 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 738 ms
69,708 KB |
testcase_03 | AC | 509 ms
50,576 KB |
testcase_04 | AC | 680 ms
32,828 KB |
testcase_05 | AC | 1,234 ms
54,440 KB |
testcase_06 | AC | 409 ms
22,408 KB |
testcase_07 | AC | 76 ms
8,108 KB |
testcase_08 | AC | 125 ms
10,400 KB |
testcase_09 | AC | 46 ms
6,244 KB |
testcase_10 | AC | 184 ms
13,040 KB |
testcase_11 | AC | 743 ms
35,556 KB |
testcase_12 | AC | 418 ms
22,672 KB |
testcase_13 | AC | 190 ms
13,428 KB |
testcase_14 | AC | 34 ms
5,672 KB |
testcase_15 | AC | 313 ms
18,448 KB |
testcase_16 | AC | 844 ms
39,552 KB |
testcase_17 | AC | 893 ms
41,008 KB |
testcase_18 | AC | 182 ms
13,040 KB |
testcase_19 | AC | 752 ms
36,324 KB |
testcase_20 | AC | 55 ms
6,772 KB |
testcase_21 | AC | 109 ms
9,676 KB |
testcase_22 | AC | 606 ms
30,368 KB |
testcase_23 | AC | 339 ms
19,504 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/c++allocator.h:33, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/allocator.h:46, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:1: In member function 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = int; _Args = {const int&}; _Tp = int]', inlined from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {const int&}; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/alloc_traits.h:516:17, inlined from 'void std::deque<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_deque.h:1543:30, inlined from 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N;; cin >> N; vector<int> in( N ); vector<vector<int>> g( N ); for( int i = 0; i < N - 1; i++ ) { int A, B; cin >> A >> B; A--; B--; g[A].push_back( B ); in[B]++; } int r; for( int i = 0; i < N; i++ ) { if( in[i] == 0 ) r = i; } vector<long long> l( N ); typedef pair<int, int> P; queue<P> que; que.push( P( r, 0 ) ); while( !que.empty() ) { int i, len; tie( i, len ) = que.front(); que.pop(); l[i] = len; for( int e : g[i] ) { que.push( P(e, len + 1) ); } } const long long MOD = 1000000000 + 7; long long ans = 0; queue<int> que1; que1.push( r ); while( !que1.empty() ) { int i = que1.front(); long long a = l[i]; que1.pop(); for( int e : g[i] ) { que1.push( e ); l[e] += a; l[e] %= MOD; ans += l[e]; ans %= MOD; } } cout << ans << endl; }