結果

問題 No.1103 Directed Length Sum
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2020-07-03 22:11:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 696 ms / 3,000 ms
コード長 2,118 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 119,440 KB
実行使用メモリ 61,952 KB
最終ジャッジ日時 2024-09-17 02:30:29
合計ジャッジ時間 8,033 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 300 ms
61,952 KB
testcase_03 AC 188 ms
38,544 KB
testcase_04 AC 362 ms
28,032 KB
testcase_05 AC 696 ms
46,184 KB
testcase_06 AC 188 ms
19,412 KB
testcase_07 AC 34 ms
7,168 KB
testcase_08 AC 55 ms
9,184 KB
testcase_09 AC 20 ms
5,632 KB
testcase_10 AC 81 ms
11,288 KB
testcase_11 AC 401 ms
30,152 KB
testcase_12 AC 218 ms
19,448 KB
testcase_13 AC 93 ms
11,592 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 155 ms
15,944 KB
testcase_16 AC 466 ms
33,728 KB
testcase_17 AC 502 ms
34,912 KB
testcase_18 AC 86 ms
11,152 KB
testcase_19 AC 421 ms
30,988 KB
testcase_20 AC 26 ms
6,144 KB
testcase_21 AC 53 ms
8,576 KB
testcase_22 AC 310 ms
25,920 KB
testcase_23 AC 167 ms
16,744 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 += (ll)dist[i]*(dist[i]+1)/2;
    ans %= mod;
  }
  cout << ans << "\n";
  return 0;
}
0