結果
| 問題 | No.1103 Directed Length Sum |
| コンテスト | |
| ユーザー |
shell_mug
|
| 提出日時 | 2020-07-03 22:33:56 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 472 ms / 3,000 ms |
| コード長 | 2,580 bytes |
| 記録 | |
| コンパイル時間 | 931 ms |
| コンパイル使用メモリ | 145,864 KB |
| 実行使用メモリ | 89,600 KB |
| 最終ジャッジ日時 | 2026-04-06 02:38:30 |
| 合計ジャッジ時間 | 5,680 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/allocator.h:46,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:45,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
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/15.2.0_1/include/c++/15/bits/alloc_traits.h:674: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/15.2.0_1/include/c++/15/bits/stl_deque.h:1610:30,
inlined from 'void std::stack<_Tp, _Sequence>::push(const value_type&) [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_stack.h:287:20,
inlined from 'int main()' at main.cpp:71:12:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/new_allocator.h:191:11: warning: 'top' may be used uninitialized [-Wm
ソースコード
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
int main (void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<int> parent(n, -1);
vector<P> e(n - 1);
vector<vector<int>> graph(n);
rep (i, n - 1) {
cin >> e[i].first >> e[i].second;
e[i].first--; e[i].second--;
graph[e[i].first].push_back(e[i].second);
parent[e[i].second] = e[i].first;
}
int top;
rep (i, n) {
if (parent[i] == -1) {
top = i;
break;
}
}
ll MOD = (ll)1e9 + 7;
vector<ll> num(n), depth(n);
vector<bool> used(n);
stack<int> st;
st.push(top);
while (!st.empty()) {
int a = st.top();
eprintf("%d ", a);
if (!used[a] && !graph[a].empty()) {
for (int i : graph[a]) {
st.push(i);
depth[i] = depth[a] + 1;
}
used[a] = true;
} else {
num[a]++;
for (int i : graph[a]) num[a] = (num[a] + num[i]) % MOD;
st.pop();
}
}
eprintf("\n");
ll ans = 0;
rep (i, n) eprintf("%lld%c", num[i], " \n"[i == i_len - 1]);
rep (i, n) eprintf("%lld%c", depth[i], " \n"[i == i_len - 1]);
rep (i, n) if (i != top) ans = (ans + num[i] * depth[i]) % MOD;
cout << ans << "\n";
return 0;
}
shell_mug