結果

問題 No.898 tri-βutree
ユーザー kuhakukuhaku
提出日時 2019-10-04 23:26:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 787 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 164,676 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2024-04-14 11:51:11
合計ジャッジ時間 13,057 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MAX3(a, b, c) (MAX((a), MAX(b, c)))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef long long ll;

#define N_MAX 100000

int parent[N_MAX][2];

int main(void){
	int n;
	cin >> n;

	REP(i, n-1){
		int u, v, w;
		cin >> u >> v >> w;
		parent[MAX(u, v)][0] = MIN(u, v);
		parent[MAX(u, v)][1] = w;
	}

	int q;
	cin >> q;

	vector<int> v(3);
	REP(i, q){
		ll ans = 0;
		cin >> v[0] >> v[1] >> v[2];

		while(1){
			int max = MAX3(v[0], v[1], v[2]);
			REP(j, 3){
				if(v[j] == max){
					v[j] = parent[v[j]][0];
				}
			}
			ans += parent[max][1];
			if(v[0] == v[1] && v[0] == v[2]) break;
		}

		cout << ans << endl;
	}

	return 0;
}
0