Submission #648620

# Submission time Handle Problem Language Result Execution time Memory
648620 2022-10-07T07:48:45 Z PoonYaPat Sprinkler (JOI22_sprinkler) C++14
0 / 100
724 ms 95548 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,q,p[200001];
ll h[200001],mul[200001][42],mod;
vector<int> adj[200001];

void dfs(int x, int par) {
    p[x]=par;
    for (auto s : adj[x]) if (s!=par) dfs(s,x);
}

void add(int node, int dis, ll val) {
    while (node!=0 && dis!=-1) {
        mul[node][dis]=(mul[node][dis]*val)%mod;
        node=p[node];
        --dis;
    }
}

void find(int node) {
    int dis=0,pre;
    ll ans=h[node];
    while (dis<=40 && node!=0) {
        ans=(ans*mul[node][dis])%mod;
        ans=(ans*mul[node][dis+1])%mod;
        pre=node;
        ++dis; node=p[node];
    }
    for (int i=dis; i<=40; ++i) { //distance can higher than root
        ans=(ans*mul[pre][dis])%mod;
    }
    cout<<ans<<"\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>mod;
    for (int i=1; i<=n; ++i) {
        for (int j=0; j<=41; ++j) mul[i][j]=1;
    }
    for (int i=0; i<n-1; ++i) {
        int a,b; cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for (int i=1; i<=n; ++i) cin>>h[i];
    dfs(1,0);
    cin>>q;
    while (q--) {
        int mode; cin>>mode;
        if (mode==1) {
            int node,dis;
            ll w;
            cin>>node>>dis>>w;
            add(node,dis,w);
        } else {
            int node; cin>>node;
            find(node);
        }
    }
}

Compilation message

sprinkler.cpp: In function 'void find(int)':
sprinkler.cpp:32:30: warning: 'pre' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |         ans=(ans*mul[pre][dis])%mod;
      |                  ~~~~~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 592 ms 91256 KB Output is correct
3 Correct 370 ms 91772 KB Output is correct
4 Correct 558 ms 94220 KB Output is correct
5 Correct 478 ms 91440 KB Output is correct
6 Correct 388 ms 90948 KB Output is correct
7 Correct 383 ms 91760 KB Output is correct
8 Correct 312 ms 92268 KB Output is correct
9 Correct 649 ms 95448 KB Output is correct
10 Correct 439 ms 95548 KB Output is correct
11 Incorrect 607 ms 91196 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 592 ms 91256 KB Output is correct
3 Correct 370 ms 91772 KB Output is correct
4 Correct 558 ms 94220 KB Output is correct
5 Correct 478 ms 91440 KB Output is correct
6 Correct 388 ms 90948 KB Output is correct
7 Correct 383 ms 91760 KB Output is correct
8 Correct 312 ms 92268 KB Output is correct
9 Correct 649 ms 95448 KB Output is correct
10 Correct 439 ms 95548 KB Output is correct
11 Incorrect 607 ms 91196 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 724 ms 92492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -