Submission #66461


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
int n;
i64 t;
vector edge(100010, vector<int>{});
vector<i64> C(100010);
vector<i64> P(100010);
i64 ans = 0;
void dfs(int u, int p, i64 num, i64 sum)
{
num = num * 10 + C[u];
num %= t;
if(num%t == 0) sum += P[u];
ans += sum;
for(auto v : edge[u])
{
if(v == p) continue;
dfs(v, u, num, sum);
}
}
int main()
{
cin >> n >> t;
rep(i, n - 1)
{
int u, v;
cin >> u >> v;
u--;
v--;
edge[u].push_back(v);
edge[v].push_back(u);
}
rep(i, n) cin >> C[i] >> P[i];
dfs(0, -1, 0, 0);
cout << ans << endl;
return 0;
}

ステータス

項目 データ
問題 1497 - Walkin' on Numbered Tree
ユーザー名 seiyu0225
投稿日時 2021-05-04 23:31:41
言語 C++17
状態 Accepted
得点 400
ソースコード長 2336 Byte
最大実行時間 119 ms
最大メモリ使用量 14208 KB

セット

セット 得点 Cases
1 ALL 400 / 400 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
s-01_in.txt AC 36 ms 4440 KB
1
s-02_in.txt AC 22 ms 4468 KB
1
s-03_in.txt AC 27 ms 4496 KB
1
s-04_in.txt AC 25 ms 4528 KB
1
t-01_in.txt AC 23 ms 4556 KB
1
t-02_in.txt AC 23 ms 4584 KB
1
t-03_in.txt AC 24 ms 4476 KB
1
t-04_in.txt AC 27 ms 4500 KB
1
t-05_in.txt AC 20 ms 4528 KB
1
t-06_in.txt AC 30 ms 4424 KB
1
t-07_in.txt AC 24 ms 4576 KB
1
t-08_in.txt AC 25 ms 4468 KB
1
t-09_in.txt AC 21 ms 4616 KB
1
t-10_in.txt AC 22 ms 4636 KB
1
t-11_in.txt AC 18 ms 4532 KB
1
t-12_in.txt AC 19 ms 4408 KB
1
t-13_in.txt AC 19 ms 4556 KB
1
t-14_in.txt AC 21 ms 4436 KB
1
t-15_in.txt AC 21 ms 4436 KB
1
t-16_in.txt AC 24 ms 4456 KB
1
t-17_in.txt AC 26 ms 4460 KB
1
t-18_in.txt AC 22 ms 4472 KB
1
t-19_in.txt AC 29 ms 4620 KB
1
t-20_in.txt AC 24 ms 4628 KB
1
t-21_in.txt AC 34 ms 4644 KB
1
t-22_in.txt AC 18 ms 4528 KB
1
t-23_in.txt AC 25 ms 4540 KB
1
t-24_in.txt AC 24 ms 4564 KB
1
t-25_in.txt AC 20 ms 4572 KB
1
t-26_in.txt AC 23 ms 4584 KB
1
t-27_in.txt AC 21 ms 4580 KB
1
t-28_in.txt AC 21 ms 4584 KB
1
t-29_in.txt AC 23 ms 4580 KB
1
t-30_in.txt AC 18 ms 4604 KB
1
t-31_in.txt AC 19 ms 4492 KB
1
t-32_in.txt AC 27 ms 4500 KB
1
t-33_in.txt AC 25 ms 4524 KB
1
t-34_in.txt AC 26 ms 4540 KB
1
t-35_in.txt AC 25 ms 4540 KB
1
t-36_in.txt AC 28 ms 4532 KB
1
t-37_in.txt AC 24 ms 4548 KB
1
t-38_in.txt AC 24 ms 4568 KB
1
t-39_in.txt AC 30 ms 4576 KB
1
t-40_in.txt AC 28 ms 4960 KB
1
t-41_in.txt AC 40 ms 5308 KB
1
t-42_in.txt AC 107 ms 6332 KB
1
t-43_in.txt AC 41 ms 5440 KB
1
t-44_in.txt AC 55 ms 6140 KB
1
t-45_in.txt AC 20 ms 4560 KB
1
t-46_in.txt AC 62 ms 6184 KB
1
t-47_in.txt AC 24 ms 4572 KB
1
t-48_in.txt AC 22 ms 4548 KB
1
t-49_in.txt AC 68 ms 6776 KB
1
t-50_in.txt AC 52 ms 6088 KB
1
t-51_in.txt AC 34 ms 5140 KB
1
t-52_in.txt AC 50 ms 5712 KB
1
t-53_in.txt AC 80 ms 7152 KB
1
t-54_in.txt AC 21 ms 4572 KB
1
t-55_in.txt AC 27 ms 4836 KB
1
t-56_in.txt AC 59 ms 6184 KB
1
t-57_in.txt AC 62 ms 6304 KB
1
t-58_in.txt AC 60 ms 6156 KB
1
t-59_in.txt AC 95 ms 7580 KB
1
t-60_in.txt AC 58 ms 6292 KB
1
t-61_in.txt AC 29 ms 4788 KB
1
t-62_in.txt AC 48 ms 5924 KB
1
t-63_in.txt AC 94 ms 7256 KB
1
t-64_in.txt AC 48 ms 5616 KB
1
t-65_in.txt AC 67 ms 6868 KB
1
t-66_in.txt AC 28 ms 5000 KB
1
t-67_in.txt AC 98 ms 8020 KB
1
t-68_in.txt AC 83 ms 7500 KB
1
t-69_in.txt AC 79 ms 7220 KB
1
t-70_in.txt AC 82 ms 6980 KB
1
t-71_in.txt AC 102 ms 8088 KB
1
t-72_in.txt AC 115 ms 8148 KB
1
t-73_in.txt AC 104 ms 7952 KB
1
t-74_in.txt AC 111 ms 8000 KB
1
t-75_in.txt AC 98 ms 8056 KB
1
t-76_in.txt AC 102 ms 7980 KB
1
t-77_in.txt AC 102 ms 8032 KB
1
t-78_in.txt AC 114 ms 8084 KB
1
t-79_in.txt AC 119 ms 8140 KB
1
t-80_in.txt AC 100 ms 14208 KB
1
t-81_in.txt AC 30 ms 4860 KB
1
t-82_in.txt AC 22 ms 4760 KB
1
t-83_in.txt AC 22 ms 4660 KB
1
t-84_in.txt AC 23 ms 4692 KB
1
t-85_in.txt AC 24 ms 4724 KB
1
t-86_in.txt AC 24 ms 4884 KB
1
t-87_in.txt AC 69 ms 6664 KB
1
t-88_in.txt AC 94 ms 7436 KB
1
t-89_in.txt AC 78 ms 7096 KB
1
t-90_in.txt AC 94 ms 7936 KB
1