結果

問題 No.1817 Reversed Edges
ユーザー MasKoaTSMasKoaTS
提出日時 2022-01-21 22:33:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,875 bytes
コンパイル時間 4,723 ms
コンパイル使用メモリ 270,500 KB
実行使用メモリ 30,848 KB
最終ジャッジ日時 2024-05-04 13:44:37
合計ジャッジ時間 17,597 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
12,320 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,248 KB
testcase_05 AC 1 ms
5,248 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 607 ms
27,520 KB
testcase_08 AC 250 ms
15,104 KB
testcase_09 AC 574 ms
26,112 KB
testcase_10 AC 305 ms
16,512 KB
testcase_11 AC 428 ms
20,480 KB
testcase_12 AC 706 ms
30,720 KB
testcase_13 AC 707 ms
30,848 KB
testcase_14 AC 668 ms
30,848 KB
testcase_15 AC 696 ms
30,848 KB
testcase_16 AC 720 ms
30,848 KB
testcase_17 AC 696 ms
30,848 KB
testcase_18 AC 714 ms
30,848 KB
testcase_19 AC 709 ms
30,848 KB
testcase_20 AC 693 ms
30,720 KB
testcase_21 AC 705 ms
30,848 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <math.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define get(type, n) type n; cin >> n; 
#define print(n) cout << (n) << endl
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define ite(i, a) for(auto& i : a)
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
#define lbi(A, x) (ll)(lb(all(A), x) - A.begin())
#define ubi(A, x) (ll)(ub(all(A), x) - A.begin())
using str = string;
using ll = long long;
using Pair = pair<int, int>;
using mint = modint1000000007;
using Mint = modint998244353;
template <class T>	using V = vector<T>;
template <class T>	using VV = V<V<T> >;
const ll INF = 9223372036854775807;
const int inf = 2147483647;
const ll mod = 1000000007;
const ll MOD = 998244353;
template <class T>  inline V<T> getList(int n) { V<T> res(n); rep(i, 0, n) { cin >> res[i]; }return res; }
template <class T>  inline VV<T> getGrid(int m, int n) { VV<T> res(m, V<T>(n)); rep(i, 0, m) { res[i] = getList<T>(n); }return res; }
template <class T> inline void prints(V<T>& vec) { cout << vec[0];	rep(i, 1, vec.size()) { cout << ' ' << vec[i]; } cout << '\n'; }
inline V<int> dtois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - '0'); } return vec; }

int count(map<V<int>, int>& mp,VV<int>& route, int a, int b) {
	if (mp.find({ a,b }) != mp.end()) {
		return mp[{a, b}];
	}
	mp[{a, b}] = 0;
	ite(nv, route[b]) {
		if (nv == a) {
			continue;
		}
		mp[{a, b}] += count(mp, route, b, nv);
	}
	mp[{a, b}] += (a > b);
	return mp[{a, b}];
}
	

int main(void) {
	get(int, n);
	VV<int> route(n, V<int>(0));
	map<V<int>, int> mp = {};
	rep(i, 0, n - 1) {
		int a, b;	cin >> a >> b;
		a--;	b--;
		route[a].push_back(b);
		route[b].push_back(a);
	}

	rep(i, 0, n) {
		int ans = 0;
		ite(nv, route[i]) {
			ans += count(mp, route, i, nv);
		}
		print(ans);
	}

	return 0;
}
0