답안 #893208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893208 2023-12-26T17:36:05 Z vjudge1 Sprinkler (JOI22_sprinkler) C++17
100 / 100
1372 ms 117872 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a) a.begin(), a.end()

int mod;
void prod(int &a, int b){
	a = (a * b) % mod;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n >> mod;
	vector< vector<int> > g(n+1);
	for(int i = 1;i < n; i++){
		int a, b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector< vector<int> > ans(n+1, vector<int>(42, 1));
	vector<int> up(n+1), h(n+1);
	for(int i = 1;i <= n; i++){
		cin >> h[i];
	}
	function<void(int, int)> dfs=[&](int v, int par){
		up[v] = par;
		for(int to : g[v]){
			if(to == par) continue;
			dfs(to, v);
		}
	};
	dfs(1, -1);
	int q; cin >> q;
	while(q--){
		int t; cin >> t;
		if(t == 1){
			int v, d, w; cin >> v >> d >> w;
			int cur = v;
			while(up[cur] != -1 && d > 0){
				prod(ans[cur][d], w);
				prod(ans[cur][d-1], w);
				cur = up[cur];
				d--;
			}
			while(d > 0){
				prod(ans[cur][d], w);
				d--;
			}
			prod(ans[cur][0], w);
		}else{
			int v; cin >> v;
			
			int product = h[v];
			for(int i = 0;i <= 40 && v != -1; i++, v = up[v]){
				prod(product, ans[v][i]);
			}
			cout << product << '\n';
			
		}
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 505 ms 100912 KB Output is correct
3 Correct 321 ms 101168 KB Output is correct
4 Correct 455 ms 111952 KB Output is correct
5 Correct 417 ms 101024 KB Output is correct
6 Correct 290 ms 100740 KB Output is correct
7 Correct 284 ms 101204 KB Output is correct
8 Correct 247 ms 101380 KB Output is correct
9 Correct 613 ms 117872 KB Output is correct
10 Correct 340 ms 116648 KB Output is correct
11 Correct 492 ms 100920 KB Output is correct
12 Correct 340 ms 101204 KB Output is correct
13 Correct 204 ms 101064 KB Output is correct
14 Correct 205 ms 101684 KB Output is correct
15 Correct 203 ms 100952 KB Output is correct
16 Correct 217 ms 101456 KB Output is correct
17 Correct 224 ms 101980 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 505 ms 100912 KB Output is correct
3 Correct 321 ms 101168 KB Output is correct
4 Correct 455 ms 111952 KB Output is correct
5 Correct 417 ms 101024 KB Output is correct
6 Correct 290 ms 100740 KB Output is correct
7 Correct 284 ms 101204 KB Output is correct
8 Correct 247 ms 101380 KB Output is correct
9 Correct 613 ms 117872 KB Output is correct
10 Correct 340 ms 116648 KB Output is correct
11 Correct 492 ms 100920 KB Output is correct
12 Correct 340 ms 101204 KB Output is correct
13 Correct 204 ms 101064 KB Output is correct
14 Correct 205 ms 101684 KB Output is correct
15 Correct 203 ms 100952 KB Output is correct
16 Correct 217 ms 101456 KB Output is correct
17 Correct 224 ms 101980 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 506 ms 100916 KB Output is correct
25 Correct 336 ms 101144 KB Output is correct
26 Correct 475 ms 117076 KB Output is correct
27 Correct 412 ms 100988 KB Output is correct
28 Correct 325 ms 100948 KB Output is correct
29 Correct 292 ms 100948 KB Output is correct
30 Correct 248 ms 101584 KB Output is correct
31 Correct 653 ms 112368 KB Output is correct
32 Correct 382 ms 116816 KB Output is correct
33 Correct 561 ms 100932 KB Output is correct
34 Correct 391 ms 101200 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 765 ms 114744 KB Output is correct
3 Correct 1136 ms 111444 KB Output is correct
4 Correct 673 ms 111816 KB Output is correct
5 Correct 588 ms 98264 KB Output is correct
6 Correct 446 ms 98408 KB Output is correct
7 Correct 356 ms 98356 KB Output is correct
8 Correct 291 ms 98632 KB Output is correct
9 Correct 776 ms 109684 KB Output is correct
10 Correct 1116 ms 113724 KB Output is correct
11 Correct 685 ms 97888 KB Output is correct
12 Correct 781 ms 98756 KB Output is correct
13 Correct 414 ms 99860 KB Output is correct
14 Correct 503 ms 100456 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 708 ms 111540 KB Output is correct
3 Correct 1372 ms 107384 KB Output is correct
4 Correct 812 ms 109688 KB Output is correct
5 Correct 632 ms 99756 KB Output is correct
6 Correct 361 ms 99924 KB Output is correct
7 Correct 349 ms 99744 KB Output is correct
8 Correct 293 ms 99660 KB Output is correct
9 Correct 908 ms 116232 KB Output is correct
10 Correct 1034 ms 114816 KB Output is correct
11 Correct 655 ms 100824 KB Output is correct
12 Correct 643 ms 98952 KB Output is correct
13 Correct 486 ms 99664 KB Output is correct
14 Correct 522 ms 100672 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 505 ms 100912 KB Output is correct
31 Correct 321 ms 101168 KB Output is correct
32 Correct 455 ms 111952 KB Output is correct
33 Correct 417 ms 101024 KB Output is correct
34 Correct 290 ms 100740 KB Output is correct
35 Correct 284 ms 101204 KB Output is correct
36 Correct 247 ms 101380 KB Output is correct
37 Correct 613 ms 117872 KB Output is correct
38 Correct 340 ms 116648 KB Output is correct
39 Correct 492 ms 100920 KB Output is correct
40 Correct 340 ms 101204 KB Output is correct
41 Correct 204 ms 101064 KB Output is correct
42 Correct 205 ms 101684 KB Output is correct
43 Correct 203 ms 100952 KB Output is correct
44 Correct 217 ms 101456 KB Output is correct
45 Correct 224 ms 101980 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 506 ms 100916 KB Output is correct
53 Correct 336 ms 101144 KB Output is correct
54 Correct 475 ms 117076 KB Output is correct
55 Correct 412 ms 100988 KB Output is correct
56 Correct 325 ms 100948 KB Output is correct
57 Correct 292 ms 100948 KB Output is correct
58 Correct 248 ms 101584 KB Output is correct
59 Correct 653 ms 112368 KB Output is correct
60 Correct 382 ms 116816 KB Output is correct
61 Correct 561 ms 100932 KB Output is correct
62 Correct 391 ms 101200 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 344 KB Output is correct
69 Correct 1 ms 344 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 344 KB Output is correct
73 Correct 1 ms 460 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 765 ms 114744 KB Output is correct
80 Correct 1136 ms 111444 KB Output is correct
81 Correct 673 ms 111816 KB Output is correct
82 Correct 588 ms 98264 KB Output is correct
83 Correct 446 ms 98408 KB Output is correct
84 Correct 356 ms 98356 KB Output is correct
85 Correct 291 ms 98632 KB Output is correct
86 Correct 776 ms 109684 KB Output is correct
87 Correct 1116 ms 113724 KB Output is correct
88 Correct 685 ms 97888 KB Output is correct
89 Correct 781 ms 98756 KB Output is correct
90 Correct 414 ms 99860 KB Output is correct
91 Correct 503 ms 100456 KB Output is correct
92 Correct 1 ms 348 KB Output is correct
93 Correct 1 ms 348 KB Output is correct
94 Correct 1 ms 348 KB Output is correct
95 Correct 1 ms 464 KB Output is correct
96 Correct 1 ms 600 KB Output is correct
97 Correct 1 ms 348 KB Output is correct
98 Correct 708 ms 111540 KB Output is correct
99 Correct 1372 ms 107384 KB Output is correct
100 Correct 812 ms 109688 KB Output is correct
101 Correct 632 ms 99756 KB Output is correct
102 Correct 361 ms 99924 KB Output is correct
103 Correct 349 ms 99744 KB Output is correct
104 Correct 293 ms 99660 KB Output is correct
105 Correct 908 ms 116232 KB Output is correct
106 Correct 1034 ms 114816 KB Output is correct
107 Correct 655 ms 100824 KB Output is correct
108 Correct 643 ms 98952 KB Output is correct
109 Correct 486 ms 99664 KB Output is correct
110 Correct 522 ms 100672 KB Output is correct
111 Correct 1 ms 348 KB Output is correct
112 Correct 1 ms 344 KB Output is correct
113 Correct 0 ms 348 KB Output is correct
114 Correct 1 ms 348 KB Output is correct
115 Correct 1 ms 348 KB Output is correct
116 Correct 707 ms 98992 KB Output is correct
117 Correct 802 ms 101468 KB Output is correct
118 Correct 690 ms 117328 KB Output is correct
119 Correct 702 ms 101308 KB Output is correct
120 Correct 494 ms 101084 KB Output is correct
121 Correct 433 ms 101716 KB Output is correct
122 Correct 302 ms 101624 KB Output is correct
123 Correct 889 ms 114192 KB Output is correct
124 Correct 1022 ms 111184 KB Output is correct
125 Correct 719 ms 100344 KB Output is correct
126 Correct 744 ms 101420 KB Output is correct
127 Correct 855 ms 102008 KB Output is correct
128 Correct 542 ms 102512 KB Output is correct
129 Correct 574 ms 103532 KB Output is correct