結果

問題 No.1637 Easy Tree Query
ユーザー karinohitokarinohito
提出日時 2021-08-06 21:29:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 4,749 ms
コンパイル使用メモリ 180,572 KB
実行使用メモリ 14,952 KB
最終ジャッジ日時 2023-10-17 04:55:42
合計ジャッジ時間 9,794 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 262 ms
11,256 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 60 ms
7,296 KB
testcase_05 AC 217 ms
6,240 KB
testcase_06 AC 139 ms
5,448 KB
testcase_07 AC 77 ms
4,348 KB
testcase_08 AC 48 ms
6,504 KB
testcase_09 AC 163 ms
9,144 KB
testcase_10 AC 97 ms
4,976 KB
testcase_11 AC 227 ms
9,672 KB
testcase_12 AC 228 ms
8,352 KB
testcase_13 AC 35 ms
5,184 KB
testcase_14 AC 99 ms
9,144 KB
testcase_15 AC 208 ms
9,936 KB
testcase_16 AC 153 ms
10,728 KB
testcase_17 AC 64 ms
5,184 KB
testcase_18 AC 200 ms
6,240 KB
testcase_19 AC 194 ms
6,768 KB
testcase_20 AC 238 ms
8,088 KB
testcase_21 AC 117 ms
7,296 KB
testcase_22 AC 243 ms
10,992 KB
testcase_23 AC 60 ms
5,448 KB
testcase_24 AC 93 ms
7,296 KB
testcase_25 AC 218 ms
5,976 KB
testcase_26 AC 246 ms
8,616 KB
testcase_27 AC 267 ms
10,464 KB
testcase_28 AC 155 ms
5,712 KB
testcase_29 AC 185 ms
7,824 KB
testcase_30 AC 55 ms
7,824 KB
testcase_31 AC 174 ms
4,348 KB
testcase_32 AC 97 ms
5,976 KB
testcase_33 AC 205 ms
5,184 KB
testcase_34 AC 75 ms
14,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;
Graph G;
vll E;
vector<bool> seen;
ll k = 0;
void dfs(int v) {
	seen[v] = true; // v を訪問済にする

	// v から行ける各頂点 next_v について
	E[v] = k;
	for (auto next_v : G[v]) {
		if (seen[next_v]) continue; // next_v が探索済だったらスルー
		k++;
		dfs(next_v); // 再帰的に探索
	}
	E[v] = k - E[v];
}

int main() {


	ll N, Q;
	cin >> N >> Q;
	G.assign(N, {});
	seen.assign(N, false);
	vll e(N, 0);
	E.assign(N, 0);
	rep(i, N - 1) {
		ll A, B;
		cin >> A >> B;
		A--; B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	dfs(0);
	ll S = 0;
	
	rep(i, Q) {
		ll P, Q;
		cin >> P >> Q;
		S += (E[P - 1]+1) * Q;
		cout << S << endl;
	}
}
0