Submission #66628


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,x,n) for(int i=(x);i<=(int)(n);i++)
#define rrep(i,n,x) for(int i=(n);i>=(int)(x);i--)
#define vi vector<int>
#define vc vector<char>
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define P pair<int,int>
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
typedef struct{
int node;
int num;
ll sum;
}hoge;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n,t; cin>>n>>t;
vi list[n+1];
rep(i,1,n-1){
int v1,v2; cin>>v1>>v2;
list[v1].pb(v2);
list[v2].pb(v1);
}
vi c(n+1),p(n+1);
rep(i,1,n){
cin>>c[i]>>p[i];
}
ll ans=0;
queue<hoge> q;
vector<bool> flag(n+1,false);
hoge st;
st.node=1;
st.num=0;
st.sum=0;
q.push(st);
flag[1]=true;
while(!q.empty()){
hoge ori;
ori=q.front();
q.pop();
ori.num=(10*ori.num+c[ori.node])%t;
if(ori.num==0){
ori.sum+=p[ori.node];
}
ans+=ori.sum;
for(int to:list[ori.node]){
if(flag[to]==false){
hoge p;
p.node=to;
p.num=ori.num;
p.sum=ori.sum;
q.push(p);
flag[to]=true;
}
}
}
cout<<ans<<"\n";
return 0;
}

ステータス

項目 データ
問題 1497 - Walkin' on Numbered Tree
ユーザー名 ei2005
投稿日時 2021-05-11 16:44:53
言語 C++17
状態 Accepted
得点 400
ソースコード長 1484 Byte
最大実行時間 69 ms
最大メモリ使用量 7600 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
s-01_in.txt AC 27 ms 604 KB
1
s-02_in.txt AC 19 ms 684 KB
1
s-03_in.txt AC 20 ms 640 KB
1
s-04_in.txt AC 21 ms 596 KB
1
t-01_in.txt AC 22 ms 420 KB
1
t-02_in.txt AC 20 ms 628 KB
1
t-03_in.txt AC 19 ms 584 KB
1
t-04_in.txt AC 18 ms 668 KB
1
t-05_in.txt AC 21 ms 620 KB
1
t-06_in.txt AC 21 ms 700 KB
1
t-07_in.txt AC 22 ms 524 KB
1
t-08_in.txt AC 33 ms 604 KB
1
t-09_in.txt AC 21 ms 552 KB
1
t-10_in.txt AC 19 ms 508 KB
1
t-11_in.txt AC 20 ms 584 KB
1
t-12_in.txt AC 19 ms 632 KB
1
t-13_in.txt AC 22 ms 700 KB
1
t-14_in.txt AC 24 ms 740 KB
1
t-15_in.txt AC 20 ms 768 KB
1
t-16_in.txt AC 24 ms 696 KB
1
t-17_in.txt AC 27 ms 604 KB
1
t-18_in.txt AC 16 ms 660 KB
1
t-19_in.txt AC 27 ms 604 KB
1
t-20_in.txt AC 26 ms 508 KB
1
t-21_in.txt AC 20 ms 560 KB
1
t-22_in.txt AC 29 ms 596 KB
1
t-23_in.txt AC 20 ms 536 KB
1
t-24_in.txt AC 19 ms 608 KB
1
t-25_in.txt AC 19 ms 644 KB
1
t-26_in.txt AC 19 ms 692 KB
1
t-27_in.txt AC 23 ms 716 KB
1
t-28_in.txt AC 18 ms 756 KB
1
t-29_in.txt AC 21 ms 656 KB
1
t-30_in.txt AC 22 ms 608 KB
1
t-31_in.txt AC 20 ms 676 KB
1
t-32_in.txt AC 19 ms 592 KB
1
t-33_in.txt AC 17 ms 672 KB
1
t-34_in.txt AC 23 ms 724 KB
1
t-35_in.txt AC 24 ms 740 KB
1
t-36_in.txt AC 25 ms 632 KB
1
t-37_in.txt AC 17 ms 568 KB
1
t-38_in.txt AC 20 ms 640 KB
1
t-39_in.txt AC 26 ms 672 KB
1
t-40_in.txt AC 23 ms 1588 KB
1
t-41_in.txt AC 26 ms 2320 KB
1
t-42_in.txt AC 40 ms 4392 KB
1
t-43_in.txt AC 27 ms 2492 KB
1
t-44_in.txt AC 33 ms 3788 KB
1
t-45_in.txt AC 22 ms 876 KB
1
t-46_in.txt AC 40 ms 4024 KB
1
t-47_in.txt AC 22 ms 812 KB
1
t-48_in.txt AC 26 ms 928 KB
1
t-49_in.txt AC 43 ms 5032 KB
1
t-50_in.txt AC 37 ms 3656 KB
1
t-51_in.txt AC 32 ms 1728 KB
1
t-52_in.txt AC 33 ms 3036 KB
1
t-53_in.txt AC 45 ms 5664 KB
1
t-54_in.txt AC 20 ms 764 KB
1
t-55_in.txt AC 25 ms 1448 KB
1
t-56_in.txt AC 43 ms 3928 KB
1
t-57_in.txt AC 43 ms 4168 KB
1
t-58_in.txt AC 42 ms 3636 KB
1
t-59_in.txt AC 52 ms 6496 KB
1
t-60_in.txt AC 35 ms 3912 KB
1
t-61_in.txt AC 32 ms 1160 KB
1
t-62_in.txt AC 35 ms 3324 KB
1
t-63_in.txt AC 55 ms 6264 KB
1
t-64_in.txt AC 38 ms 2712 KB
1
t-65_in.txt AC 39 ms 5228 KB
1
t-66_in.txt AC 20 ms 1348 KB
1
t-67_in.txt AC 63 ms 7412 KB
1
t-68_in.txt AC 57 ms 6360 KB
1
t-69_in.txt AC 43 ms 6068 KB
1
t-70_in.txt AC 50 ms 5296 KB
1
t-71_in.txt AC 69 ms 7520 KB
1
t-72_in.txt AC 60 ms 7516 KB
1
t-73_in.txt AC 57 ms 7500 KB
1
t-74_in.txt AC 61 ms 7596 KB
1
t-75_in.txt AC 69 ms 7548 KB
1
t-76_in.txt AC 67 ms 7528 KB
1
t-77_in.txt AC 59 ms 7500 KB
1
t-78_in.txt AC 62 ms 7600 KB
1
t-79_in.txt AC 58 ms 7580 KB
1
t-80_in.txt AC 50 ms 7176 KB
1
t-81_in.txt AC 23 ms 860 KB
1
t-82_in.txt AC 23 ms 940 KB
1
t-83_in.txt AC 22 ms 772 KB
1
t-84_in.txt AC 22 ms 856 KB
1
t-85_in.txt AC 18 ms 808 KB
1
t-86_in.txt AC 23 ms 884 KB
1
t-87_in.txt AC 48 ms 4736 KB
1
t-88_in.txt AC 45 ms 6300 KB
1
t-89_in.txt AC 50 ms 5732 KB
1
t-90_in.txt AC 57 ms 7036 KB
1