結果

問題 No.1817 Reversed Edges
ユーザー kwm_tkwm_t
提出日時 2022-01-21 22:40:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,766 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 204,292 KB
実行使用メモリ 19,280 KB
最終ジャッジ日時 2023-08-17 06:59:14
合計ジャッジ時間 5,485 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,056 KB
testcase_01 AC 4 ms
8,028 KB
testcase_02 AC 5 ms
8,024 KB
testcase_03 AC 4 ms
8,304 KB
testcase_04 AC 4 ms
8,040 KB
testcase_05 AC 4 ms
8,112 KB
testcase_06 AC 5 ms
8,148 KB
testcase_07 AC 61 ms
12,808 KB
testcase_08 AC 28 ms
10,004 KB
testcase_09 AC 55 ms
12,560 KB
testcase_10 AC 31 ms
10,376 KB
testcase_11 AC 41 ms
11,072 KB
testcase_12 AC 69 ms
13,196 KB
testcase_13 AC 68 ms
13,232 KB
testcase_14 AC 70 ms
13,208 KB
testcase_15 AC 70 ms
13,196 KB
testcase_16 AC 68 ms
13,180 KB
testcase_17 AC 67 ms
13,340 KB
testcase_18 AC 68 ms
13,284 KB
testcase_19 AC 68 ms
13,176 KB
testcase_20 AC 68 ms
13,224 KB
testcase_21 AC 68 ms
13,292 KB
testcase_22 AC 35 ms
13,628 KB
testcase_23 AC 37 ms
13,600 KB
testcase_24 AC 48 ms
19,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int in[100005];
int out[100005];
vector<int>to[200005];
int c;
void dfs(int v, int d = 0, int p = -1) {
	in[v] = c;
	c++;
	for (int e : to[v]) {
		if (p == e) continue;
		dfs(e, d + 1, v);
	}
	out[v] = c;
	c++;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<P>edge(n - 1);
	rep(i, n - 1) {
		int a, b; cin >> a >> b; a--; b--;
		to[a].push_back(b);
		to[b].push_back(a);
		edge[i] = { min(a,b),max(a,b) };
	}
	dfs(0);
	vector<int>sum(2 * n + 1);
	/*rep(i, n) cout << in[i];
	cout << endl;
	rep(i, n) cout << out[i];
	cout << endl;*/
	rep(i, n - 1) {
		int l = edge[i].first;
		int r = edge[i].second;
		//cout << in[r] << " " << out[r] << endl;
		if (in[l] < in[r]) {
			sum[in[r]]++;
			sum[out[r] + 1]--;
		}
		else {
			sum[0]++;
			sum[2 * n + 1]--;
			sum[in[l]]--;
			sum[out[l] + 1]++;
		}
	}
	rep(i, n * 2)sum[i + 1] += sum[i];
	rep(i, n) cout << sum[in[i]] << endl;
	return 0;
}
0