結果

問題 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,043 ms
コンパイル使用メモリ 119,408 KB
実行使用メモリ 62,012 KB
最終ジャッジ日時 2024-09-17 02:30:06
合計ジャッジ時間 6,406 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 WA -
testcase_03 AC 163 ms
38,532 KB
testcase_04 AC 218 ms
27,920 KB
testcase_05 AC 524 ms
46,188 KB
testcase_06 AC 157 ms
19,456 KB
testcase_07 AC 29 ms
7,168 KB
testcase_08 AC 45 ms
9,136 KB
testcase_09 AC 19 ms
6,944 KB
testcase_10 AC 65 ms
11,460 KB
testcase_11 AC 293 ms
30,128 KB
testcase_12 AC 125 ms
19,528 KB
testcase_13 AC 61 ms
11,548 KB
testcase_14 AC 13 ms
6,940 KB
testcase_15 AC 96 ms
15,932 KB
testcase_16 AC 326 ms
33,688 KB
testcase_17 AC 314 ms
35,032 KB
testcase_18 AC 58 ms
11,272 KB
testcase_19 AC 304 ms
30,956 KB
testcase_20 AC 20 ms
6,940 KB
testcase_21 AC 34 ms
8,576 KB
testcase_22 AC 211 ms
25,780 KB
testcase_23 AC 109 ms
16,708 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