結果

問題 No.1103 Directed Length Sum
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2020-07-03 22:10:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,114 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 120,032 KB
実行使用メモリ 61,844 KB
最終ジャッジ日時 2023-10-17 03:49:55
合計ジャッジ時間 8,387 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 183 ms
38,664 KB
testcase_04 AC 344 ms
28,256 KB
testcase_05 AC 651 ms
46,268 KB
testcase_06 AC 182 ms
19,528 KB
testcase_07 AC 33 ms
7,152 KB
testcase_08 AC 53 ms
9,264 KB
testcase_09 AC 20 ms
5,652 KB
testcase_10 AC 81 ms
11,308 KB
testcase_11 AC 387 ms
30,240 KB
testcase_12 AC 197 ms
19,620 KB
testcase_13 AC 86 ms
11,572 KB
testcase_14 AC 15 ms
5,096 KB
testcase_15 AC 146 ms
16,076 KB
testcase_16 AC 445 ms
33,604 KB
testcase_17 AC 474 ms
34,924 KB
testcase_18 AC 84 ms
11,308 KB
testcase_19 AC 485 ms
31,032 KB
testcase_20 AC 54 ms
6,124 KB
testcase_21 AC 104 ms
8,736 KB
testcase_22 AC 590 ms
25,820 KB
testcase_23 AC 334 ms
16,784 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/ostream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
                 from main.cpp:1:
In member function 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = int; _Args = {int&}; _Tp = int]',
    inlined from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {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>::emplace_back(_Args&& ...) [with _Args = {int&}; _Tp = int; _Alloc = std::allocator<int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/deque.tcc:170:30,
    inlined from 'void std::queue<_Tp, _Sequence>::emplace(_Args&& ...) [with _Args = {int&}; _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_queue.h:302:18,
    inlined from 'int main()' at main.cpp:59:14:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/new_allocator.h:175:11: warning: 'root' may be used uninitialized [-Wmaybe-uninitialized]
  175 |         { ::new((void *)__p) _Up(std::forward<_Args

ソースコード

diff #

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<bool> used(N,false);
  vector<vector<int>> G(N);
  for(int i=0; i<N-1; i++){
    int a,b;
    cin >> a >> b;
    a--;b--;
    G[a].emplace_back(b);
    used[b] = true;
  }
  int root;
  for(int i=0; i<N; i++) if(!used[i]) root = i;
  queue<int> que;
  vector<int> dist(N,-1);
  dist[root] = 0;
  que.emplace(root);
  while(que.size()){
    int v = que.front();
    que.pop();
    for(int nv : G[v]){
      dist[nv] = dist[v] + 1;
      que.emplace(nv);
    }
  }
  ll ans = 0;
  for(int i=0; i<N; i++){
    ans += dist[i]*(dist[i]+1)/2;
    ans %= mod;
  }
  cout << ans << "\n";
  return 0;
}
0