답안 #877423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877423 2023-11-23T08:34:44 Z serkanrashid Sprinkler (JOI22_sprinkler) C++14
0 / 100
4000 ms 92228 KB
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

const int maxn = 2*1e5+5;

long long n,l,q;
long long type,x,d,w;
long long h[maxn],par[maxn];
long long dp[maxn][42];
vector<int>g[maxn];
long long ans;

void dfs(int beg, int p)
{
    par[beg] = p;
    for(int nb:g[beg])
    {
        if(nb!=p) dfs(nb,beg);
    }
}

void dfs1(int beg, int d, long long w)
{
    if(d<0) return;
    dp[beg][d] = (dp[beg][d]*w)%l;
    d--;
    if(d<0) return;
    dp[beg][d] = (dp[beg][d]*w)%l;
    if(par[beg]==beg) d--;
    dfs1(par[beg],d,w);
}

void dfs2(int beg, int d)
{
    ans = (ans*dp[beg][d])%l;
    if(beg!=par[beg]) dfs2(par[beg],d+1);
}

void read()
{
    cin >> n >> l;
    for(int i=1;i<=n;i++)
    {
        for(int z=0;z<=41;z++) dp[i][z] = 1;
    }
    int a,b;
    for(int i=1;i<n;i++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=1;i<=n;i++) cin >> h[i];
    dfs(1,1);
    cin >> q;
    for(int i=1;i<=q;i++)
    {
        cin >> type >> x;
        /*for(int j=1;j<=n;j++)
        {
            cout << j << "->";
            for(int z=0;z<=n;z++)
            {
                cout << " " << dp[j][z];
            }
            cout << endl;
        }*/
        if(type==2)
        {
            ans = h[x];
            dfs2(x,0);
            cout << ans << endl;

        }
        else
        {
            cin >> d >> w;
            dfs1(x,d,w);
        }
        /*for(int j=1;j<=n;j++)
        {
            cout << j << "->";
            for(int z=0;z<=n;z++)
            {
                cout << " " << dp[j][z];
            }
            cout << endl;
        }
        cout << "+++++++++" << " " << "end query" << endl;*/
    }
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	read();
return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Incorrect 3 ms 8860 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Incorrect 3052 ms 92228 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Incorrect 3052 ms 92228 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Execution timed out 4075 ms 90504 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Execution timed out 4077 ms 89008 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Incorrect 3 ms 8860 KB Output isn't correct
5 Halted 0 ms 0 KB -