結果

問題 No.1637 Easy Tree Query
ユーザー kakao745kakao745
提出日時 2024-09-18 15:47:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,976 bytes
コンパイル時間 3,422 ms
コンパイル使用メモリ 257,308 KB
実行使用メモリ 10,224 KB
最終ジャッジ日時 2024-09-18 15:47:42
合計ジャッジ時間 11,338 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 253 ms
10,224 KB
testcase_03 WA -
testcase_04 AC 51 ms
6,940 KB
testcase_05 AC 192 ms
6,944 KB
testcase_06 AC 129 ms
6,940 KB
testcase_07 AC 70 ms
6,944 KB
testcase_08 AC 44 ms
6,944 KB
testcase_09 AC 150 ms
8,320 KB
testcase_10 AC 92 ms
6,944 KB
testcase_11 AC 240 ms
8,960 KB
testcase_12 AC 229 ms
7,680 KB
testcase_13 AC 34 ms
6,940 KB
testcase_14 AC 89 ms
8,448 KB
testcase_15 AC 198 ms
9,344 KB
testcase_16 AC 160 ms
9,856 KB
testcase_17 AC 62 ms
6,940 KB
testcase_18 AC 183 ms
6,940 KB
testcase_19 AC 177 ms
6,940 KB
testcase_20 AC 220 ms
7,552 KB
testcase_21 AC 105 ms
6,944 KB
testcase_22 AC 223 ms
9,984 KB
testcase_23 AC 55 ms
6,944 KB
testcase_24 AC 84 ms
6,940 KB
testcase_25 AC 230 ms
6,940 KB
testcase_26 AC 219 ms
7,808 KB
testcase_27 AC 243 ms
9,728 KB
testcase_28 AC 143 ms
6,940 KB
testcase_29 AC 175 ms
7,296 KB
testcase_30 AC 48 ms
7,296 KB
testcase_31 AC 179 ms
6,944 KB
testcase_32 AC 85 ms
6,940 KB
testcase_33 AC 190 ms
6,944 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/modint>
using namespace atcoder;
using mint=modint998244353;
#define itn int
#define rep(i,n) for(long long i=0;i<(long long)n;i++)
#define reps(i,n) for(long long i=1;i<=(long long)n;i++)
#define loop(i,l,r) for(long long i=l;i<=(long long)r;i++)
#define drep(i,n) for(long long i=(long long)n-1;i>=0;i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yn(x) cout << (x? "Yes":"No") << endl;
#define cou(x) cout << x << endl;
#define emp emplace_back
#pragma GCC target ("avx,avx2")//四則演算
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")//ループ
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")//浮動小数点
const long long mod=998244353LL;
const long long mods=1000000007LL;
const double inf=numeric_limits<double>::infinity();
const int kaz=1000000000;
const long long yab=2500000000000000000LL;
const long long aho =-yab;
const long double eps=1.0e-14L;
const long double pi=acosl(-1.0L);
using ll=long long;
using st=string;
using P=pair<ll,ll>;
using tup=tuple<ll,ll,ll>;
using vi=vector<ll>;
using vin=vector<int>;
using vc=vector<char>;
using vb=vector<bool>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using sp=set<P>;
using si=set<ll>;
using vvi=vector<vector<ll>>;
using vvin=vector<vin>;
using vvc=vector<vc>;
using vvb=vector<vb>;
using vvvi=vector<vvi>;
using vvvin=vector<vvin>;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const vector<int> ex = {-1, -1, -1, 0, 0, 1, 1, 1};
const vector<int> ey = {-1, 0, 1, -1, 1, -1, 0, 1};
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>v){rep(i,v.size())os<<v[i]<<(i+1!=v.size()?" ":"\n");return os;}
template<typename T1,typename T2>
void co(bool x,T1 y,T2 z){
  if(x)cout << y << endl;
  else cout << z << endl;
}
template<typename T>
bool chmax(T &a, T b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<typename T>
bool chmin(T &a, T b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<typename T>
void print(vector<T> &a){
	for(int i=0;i<a.size();i++){
		cout << a[i];
		if(i==(long long)a.size()-1)cout << endl;
		else cout << " ";
	}
}
ll mypow(ll x,ll y){
	ll ret=1;
	while(y>0){
		if(y&1)ret=ret*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ret;
}
ll nopow(ll x,ll y){
	ll ret=1;
	while(y>0){
		if(y&1)ret*=x;
		x*=x;
		y>>=1;
	}
	return ret;
}
void f(int prev,int j,vi &dp,vvi &g){
	if(g[j].size()==1){dp[j]=1;return;}
	if(g[j].size()!=0){
		for(auto e:g[j]){
			if(e==prev)continue;
			f(j,e,dp,g);
			dp[j]+=dp[e];
		}
		dp[j]++;
	}
}
int main(){
	int n,q;
	cin >> n >> q;
	vvi g(n);
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].emp(b);
		g[b].emp(a);
	}
	vi dp(n);
	f(-1,0,dp,g);
	ll res=0;
	rep(i,q){
		int a,b;
		cin >> a >> b;
		res+=dp[--a]*b;
		cout << res << endl;
	}
	
}
0