結果

問題 No.2638 Initial fare
ユーザー forest3forest3
提出日時 2024-03-05 17:31:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 699 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 184,948 KB
実行使用メモリ 76,092 KB
最終ジャッジ日時 2024-03-05 17:31:57
合計ジャッジ時間 8,058 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 2 ms
6,676 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)

int main() {
	int N;
	cin >> N;
	vector<vector<int>> g(N);
	rep(i, N - 1) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	using P = pair<int, int>;
	using T = tuple<int, int, int>;
	set<P> st;
	rep(i, N) {
		queue<T> q;
		q.push(T(i, 0, -1));
		while(q.size()) {
			int u, d, p;
			tie(u, d, p) = q.front();
			q.pop();
			if(d >= 3) continue;
			for( int e : g[u]) {
				if(e == p) continue;
				int a = e;
				int b = i;
				if(a > b) swap(a, b);
				st.insert(P(a, b));
				q.push(T(e, d + 1, u));
			}
		}
	}
	cout << st.size() << endl;
}
0