이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, L; cin >> n >> L;
vector <vector<int>> G(n);
for ( int i = 0; i + 1 < n; i++ ){
int u, v; cin >> u >> v;
--u, --v;
G[u].pb(v), G[v].pb(u);
}
vector <int> h(n);
for ( auto &u: h ) cin >> u;
int q; cin >> q;
vector <ar<int,4>> Q(q);
for ( auto &[t, x, d, w]: Q ){
cin >> t >> x;
--x;
if ( t == 1 ){
cin >> d >> w;
}
}
if ( min(n, q) <= 1000 ){ // subtask #1
for ( auto &[t, x, d, w]: Q ){
if ( t == 1 ){
auto dfs = [&](auto dfs, int u, int p, int D) -> void{
h[u] = h[u] * w % L;
if ( D != d ){
for ( auto &v: G[u] ){
if ( v != p ){
dfs(dfs, v, u, D + 1);
}
}
}
};
dfs(dfs, x, -1, 0);
} else cout << h[x] << ln;
}
return 0;
}
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |