Submission #785471

# Submission time Handle Problem Language Result Execution time Memory
785471 2023-07-17T09:25:24 Z andecaandeci Sprinkler (JOI22_sprinkler) C++17
3 / 100
4000 ms 17928 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int dis[200005], h[200005];
vector<int> adjl[200005];
int n, l, a, b;

int kali(int a, int b) {
  return ((a%l)*(b%l))%l;
}

void bfs(int start, int d, int w) {
  queue<int> q;
  memset(dis, -1, sizeof(dis));
  q.push(start);
  dis[start] = 0;
  h[start] = kali(h[start], w);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();

    for (auto i: adjl[cur]) {
      if (dis[i] == -1) {
        dis[i] = dis[cur]+1;
        if (dis[i] <= d) {
          
          h[i] = kali(h[i], w);
          if (dis[i] < d) {
            q.push(i);
          }
        }
      }
    }
  }
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> l;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    adjl[a].push_back(b);
    adjl[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) cin >> h[i];

  int q, t, x, d, w;
  cin >> q;
  while (q--) {
    cin >> t;
    if (t == 1) {
      cin >> x >> d >> w;
      if (d == 0) h[x] = kali(h[x], w);
      else if (d == 1) {
        h[x] = kali(h[x], w);
        for (auto i: adjl[x]) h[i] = kali(h[i], w);
      }
      else bfs(x, d, w);
    }
    else if (t == 2) {
      cin >> x;
      cout << h[x]%l << endl;
    }
  }

}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 16 ms 6628 KB Output is correct
5 Correct 20 ms 6560 KB Output is correct
6 Correct 23 ms 6644 KB Output is correct
7 Correct 23 ms 6644 KB Output is correct
8 Correct 24 ms 6652 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 8 ms 6484 KB Output is correct
15 Correct 9 ms 6484 KB Output is correct
16 Correct 8 ms 6604 KB Output is correct
17 Correct 10 ms 6484 KB Output is correct
18 Correct 8 ms 6484 KB Output is correct
19 Correct 7 ms 6484 KB Output is correct
20 Correct 10 ms 6484 KB Output is correct
21 Correct 8 ms 6484 KB Output is correct
22 Correct 8 ms 6484 KB Output is correct
23 Correct 8 ms 6484 KB Output is correct
24 Correct 8 ms 6596 KB Output is correct
25 Correct 8 ms 6484 KB Output is correct
26 Correct 9 ms 6484 KB Output is correct
27 Correct 8 ms 6484 KB Output is correct
28 Correct 8 ms 6596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 537 ms 17396 KB Output is correct
3 Correct 260 ms 14212 KB Output is correct
4 Correct 397 ms 14684 KB Output is correct
5 Correct 379 ms 15840 KB Output is correct
6 Correct 399 ms 15804 KB Output is correct
7 Correct 374 ms 16236 KB Output is correct
8 Correct 375 ms 16336 KB Output is correct
9 Correct 528 ms 16160 KB Output is correct
10 Correct 252 ms 13144 KB Output is correct
11 Correct 542 ms 17328 KB Output is correct
12 Correct 261 ms 14140 KB Output is correct
13 Execution timed out 4054 ms 14176 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 537 ms 17396 KB Output is correct
3 Correct 260 ms 14212 KB Output is correct
4 Correct 397 ms 14684 KB Output is correct
5 Correct 379 ms 15840 KB Output is correct
6 Correct 399 ms 15804 KB Output is correct
7 Correct 374 ms 16236 KB Output is correct
8 Correct 375 ms 16336 KB Output is correct
9 Correct 528 ms 16160 KB Output is correct
10 Correct 252 ms 13144 KB Output is correct
11 Correct 542 ms 17328 KB Output is correct
12 Correct 261 ms 14140 KB Output is correct
13 Execution timed out 4054 ms 14176 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6612 KB Output is correct
2 Correct 1773 ms 15292 KB Output is correct
3 Execution timed out 4082 ms 14408 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6584 KB Output is correct
2 Correct 1856 ms 17928 KB Output is correct
3 Execution timed out 4067 ms 14452 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 16 ms 6628 KB Output is correct
5 Correct 20 ms 6560 KB Output is correct
6 Correct 23 ms 6644 KB Output is correct
7 Correct 23 ms 6644 KB Output is correct
8 Correct 24 ms 6652 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 8 ms 6484 KB Output is correct
15 Correct 9 ms 6484 KB Output is correct
16 Correct 8 ms 6604 KB Output is correct
17 Correct 10 ms 6484 KB Output is correct
18 Correct 8 ms 6484 KB Output is correct
19 Correct 7 ms 6484 KB Output is correct
20 Correct 10 ms 6484 KB Output is correct
21 Correct 8 ms 6484 KB Output is correct
22 Correct 8 ms 6484 KB Output is correct
23 Correct 8 ms 6484 KB Output is correct
24 Correct 8 ms 6596 KB Output is correct
25 Correct 8 ms 6484 KB Output is correct
26 Correct 9 ms 6484 KB Output is correct
27 Correct 8 ms 6484 KB Output is correct
28 Correct 8 ms 6596 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 537 ms 17396 KB Output is correct
31 Correct 260 ms 14212 KB Output is correct
32 Correct 397 ms 14684 KB Output is correct
33 Correct 379 ms 15840 KB Output is correct
34 Correct 399 ms 15804 KB Output is correct
35 Correct 374 ms 16236 KB Output is correct
36 Correct 375 ms 16336 KB Output is correct
37 Correct 528 ms 16160 KB Output is correct
38 Correct 252 ms 13144 KB Output is correct
39 Correct 542 ms 17328 KB Output is correct
40 Correct 261 ms 14140 KB Output is correct
41 Execution timed out 4054 ms 14176 KB Time limit exceeded
42 Halted 0 ms 0 KB -