結果

問題 No.1817 Reversed Edges
ユーザー bonKotsubonKotsu
提出日時 2022-07-27 23:29:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,101 bytes
コンパイル時間 4,323 ms
コンパイル使用メモリ 258,648 KB
実行使用メモリ 13,904 KB
最終ジャッジ日時 2023-09-24 12:05:38
合計ジャッジ時間 9,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,732 KB
testcase_01 AC 3 ms
5,856 KB
testcase_02 AC 3 ms
5,760 KB
testcase_03 AC 3 ms
5,728 KB
testcase_04 AC 3 ms
5,824 KB
testcase_05 AC 4 ms
5,784 KB
testcase_06 AC 3 ms
5,780 KB
testcase_07 AC 77 ms
8,928 KB
testcase_08 AC 37 ms
7,284 KB
testcase_09 AC 71 ms
8,736 KB
testcase_10 AC 42 ms
7,516 KB
testcase_11 AC 52 ms
8,056 KB
testcase_12 AC 88 ms
9,332 KB
testcase_13 AC 93 ms
9,332 KB
testcase_14 AC 94 ms
9,364 KB
testcase_15 AC 93 ms
9,336 KB
testcase_16 AC 92 ms
9,372 KB
testcase_17 AC 91 ms
9,340 KB
testcase_18 AC 94 ms
9,368 KB
testcase_19 AC 98 ms
9,444 KB
testcase_20 AC 95 ms
9,352 KB
testcase_21 AC 96 ms
9,468 KB
testcase_22 AC 61 ms
9,556 KB
testcase_23 AC 62 ms
9,464 KB
testcase_24 AC 79 ms
13,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };

int dist[100005];
vector<int> g[100005];
int ans[100005];

void dfs(int v, int p = -1) {
  if (p != -1 && v < p) ans[0]++;
  for (auto nv : g[v]) {
    if (nv == p) continue;
    dfs(nv, v);
  }
  return;
}

void dfs2(int v, int p = -1) {
  if (p != -1 && v < p) ans[v] = ans[p]-1;
  if (p != -1 && v > p) ans[v] = ans[p]+1;
  for (auto nv : g[v]) {
    if (nv == p) continue;
    dfs2(nv, v);
  }
  return;

}

int main() {
  int n;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  dfs(0);
  dfs2(0);
  rep(i,n) cout << ans[i] << "\n";
  
  return 0;
}
0