結果
| 問題 |
No.1103 Directed Length Sum
|
| コンテスト | |
| ユーザー |
forest3
|
| 提出日時 | 2020-07-04 22:23:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,083 ms / 3,000 ms |
| コード長 | 884 bytes |
| コンパイル時間 | 1,694 ms |
| コンパイル使用メモリ | 181,672 KB |
| 実行使用メモリ | 69,632 KB |
| 最終ジャッジ日時 | 2024-09-19 13:55:31 |
| 合計ジャッジ時間 | 13,560 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
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;
}
forest3