답안 #785548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785548 2023-07-17T10:11:18 Z amukkalir Sprinkler (JOI22_sprinkler) C++17
15 / 100
1178 ms 25324 KB
#include "bits/stdc++.h"
using namespace std; 

typedef long long ll; 
#define pii pair<int,int> 
#define fi first 
#define se second 
#define pb push_back

const int N = 2e5; 
long long h[N+5]; 
int n, l; 
vector<int> adj[N+5]; 
bool vis[N+5][45];

void dfs (int u, int prv, long long w, int dst) {
    if (dst < 0) return; 
    h[u] *= w; 
    h[u] %= l;
    //cerr << u << " lalala " << h[u] << endl;  
    for (int v : adj[u]) {
        if (v==prv) continue; 
        dfs(v, u, w, dst-1); 
    }
}

void dfs4 (int u, int prv, long long w, int dst) {
    if (dst < 0) return; 
    if (vis[u][dst]) return; 
    vis[u][dst] = true; 
    h[u] *= w; 
    h[u] %= l;
    //cerr << u << " lalala " << h[u] << endl;  
    for (int v : adj[u]) {
        if (v==prv) continue; 
        dfs4(v, u, w, dst-1); 
    }
}

void sub4() {
    int q; cin>>q; 
    while (q--) {
        int tp; 
        cin >> tp; 
        if (tp == 1) {
            int x, d, w; 
            cin >> x >> d >> w; 
            dfs4(x, 0, w, d); 
        } else {
            int x;
            cin >> x; 
            cout << h[x] << endl; 
        }
    }
}

void sub1() {
    int q; cin>>q; 
    while (q--) {
        int tp; 
        cin >> tp; 
        if (tp == 1) {
            int x, d, w; 
            cin >> x >> d >> w; 
            dfs(x, 0, w, d); 
        } else {
            int x;
            cin >> x; 
            cout << h[x] << endl; 
        }
    }
}

signed main () {
    int t=1; 
    //scanf("%d", &t);
    while(t--) {
        cin >> n >> l; 
        for(int i=1; i<n; i++) {
            int a, b; 
            cin >> a >> b; 
            adj[a].pb(b);
            adj[b].pb(a); 
        }
        for (int i=1; i<=n; i++) {
            cin >> h[i]; 
        } 
        if (n <= 1000) sub1(); 
        else sub4(); 
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 5 ms 4948 KB Output is correct
6 Correct 7 ms 4948 KB Output is correct
7 Correct 8 ms 4948 KB Output is correct
8 Correct 8 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4916 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 5020 KB Output is correct
26 Correct 4 ms 4956 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 791 ms 25204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 791 ms 25204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 1026 ms 22464 KB Output is correct
3 Correct 734 ms 21580 KB Output is correct
4 Correct 999 ms 22036 KB Output is correct
5 Correct 1043 ms 22072 KB Output is correct
6 Correct 1178 ms 22136 KB Output is correct
7 Correct 1086 ms 22372 KB Output is correct
8 Correct 828 ms 22772 KB Output is correct
9 Correct 941 ms 22380 KB Output is correct
10 Correct 875 ms 21680 KB Output is correct
11 Correct 980 ms 22360 KB Output is correct
12 Correct 845 ms 21904 KB Output is correct
13 Correct 758 ms 22648 KB Output is correct
14 Correct 806 ms 23040 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 908 ms 25324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 5 ms 4948 KB Output is correct
6 Correct 7 ms 4948 KB Output is correct
7 Correct 8 ms 4948 KB Output is correct
8 Correct 8 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 4 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4916 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 4 ms 5020 KB Output is correct
26 Correct 4 ms 4956 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 4 ms 4948 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Incorrect 791 ms 25204 KB Output isn't correct
31 Halted 0 ms 0 KB -