이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
}
int lst[N+5];
int sqr;
int mul (ll a, ll b) {
int res = (a*b) % l;
return res;
}
long long ht[N+5];
void dfs2 (int u, int prv, long long w, int dst) {
ht[u] = mul(ht[u], w);
if (dst == 0) return;
//cerr << u << " lalala " << h[u] << endl;
if (dst==1 && adj[u].size() < sqr) {
for (int v : adj[u]) {
if (v==prv) continue;
dfs2(v, u, w, dst-1);
}
}
}
void sub2() {
int q; cin>>q;
sqr = sqrt(n);
for(int i=1; i<=n; i++) {
ht[i] = 1;
}
for(int tm = 1; tm <= q; tm++) {
int tp;
cin >> tp;
if (tp == 1) {
int x, d, w;
cin >> x >> d >> w;
if (d == 0) h[x] = mul(h[x], w);
else dfs2(x, 0, w, d);
} else {
int x;
cin >> x;
ll res = mul(h[x], ht[x]);
if (adj[x].size() < sqr) {
for (int u : adj[x]) {
res = mul(res, ht[u]);
}
}
cout << res << endl;
}
}
}
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 sub2();
}
}
컴파일 시 표준 에러 (stderr) 메시지
sprinkler.cpp: In function 'void dfs2(int, int, long long int, int)':
sprinkler.cpp:55:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | if (dst==1 && adj[u].size() < sqr) {
| ~~~~~~~~~~~~~~^~~~~
sprinkler.cpp: In function 'void sub2()':
sprinkler.cpp:81:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
81 | if (adj[x].size() < sqr) {
| ~~~~~~~~~~~~~~^~~~~
# | 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... |