結果
問題 | No.1637 Easy Tree Query |
ユーザー | ゆきのん |
提出日時 | 2021-08-06 21:24:40 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 237 ms / 2,000 ms |
コード長 | 1,328 bytes |
コンパイル時間 | 2,801 ms |
コンパイル使用メモリ | 205,044 KB |
実行使用メモリ | 13,804 KB |
最終ジャッジ日時 | 2023-10-17 04:43:34 |
合計ジャッジ時間 | 9,936 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,724 KB |
testcase_01 | AC | 3 ms
6,728 KB |
testcase_02 | AC | 232 ms
10,108 KB |
testcase_03 | AC | 3 ms
6,724 KB |
testcase_04 | AC | 51 ms
8,524 KB |
testcase_05 | AC | 193 ms
7,996 KB |
testcase_06 | AC | 126 ms
7,732 KB |
testcase_07 | AC | 69 ms
6,796 KB |
testcase_08 | AC | 41 ms
8,260 KB |
testcase_09 | AC | 142 ms
9,316 KB |
testcase_10 | AC | 89 ms
7,732 KB |
testcase_11 | AC | 194 ms
9,580 KB |
testcase_12 | AC | 203 ms
9,052 KB |
testcase_13 | AC | 32 ms
7,732 KB |
testcase_14 | AC | 84 ms
9,316 KB |
testcase_15 | AC | 181 ms
9,844 KB |
testcase_16 | AC | 133 ms
10,108 KB |
testcase_17 | AC | 56 ms
7,732 KB |
testcase_18 | AC | 177 ms
7,996 KB |
testcase_19 | AC | 174 ms
8,260 KB |
testcase_20 | AC | 214 ms
9,052 KB |
testcase_21 | AC | 104 ms
8,524 KB |
testcase_22 | AC | 221 ms
10,108 KB |
testcase_23 | AC | 55 ms
7,732 KB |
testcase_24 | AC | 80 ms
8,524 KB |
testcase_25 | AC | 197 ms
7,996 KB |
testcase_26 | AC | 213 ms
9,052 KB |
testcase_27 | AC | 237 ms
9,844 KB |
testcase_28 | AC | 139 ms
7,996 KB |
testcase_29 | AC | 162 ms
8,788 KB |
testcase_30 | AC | 46 ms
8,788 KB |
testcase_31 | AC | 156 ms
6,736 KB |
testcase_32 | AC | 86 ms
7,996 KB |
testcase_33 | AC | 190 ms
7,732 KB |
testcase_34 | AC | 62 ms
13,804 KB |
ソースコード
#include<bits/stdc++.h> //#include<atcoder/all> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; //using namespace atcoder; //using namespace boost::multiprecision; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long ll; typedef pair<ll,ll> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;} const ll mod=1e9 + 7; const ll LINF=1ll<<60; const int INF=1<<30; int dx[]={0,1,0,-1,0,1,-1,1,-1}; int dy[]={0,0,1,0,-1,1,-1,-1,1}; vector<int> G[1<<17]; vector<int> c(1<<17, 0); int dfs(int u,int v){ int ret = 1; for(auto g:G[u]){ if(g == v) continue; ret += dfs(g, u); } return c[u] = ret; } int main(){ int n,q;cin >>n >> q; for (int i = 0; i < n-1; i++) { int a,b;cin >> a >> b; a--,b--; G[a].pb(b); G[b].pb(a); } dfs(0, 0); ll ans = 0; for (int i = 0; i < q; i++) { ll p,x;cin >> p >> x; p--; ans += c[p] * x; cout << ans << endl; } return 0; }