#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
#define long long long
using namespace std;
const int V = (int) 1.5E5;
int n, m, x;
vector<pair<int, int>> e[V];
int t[V];
int p[V * 2];
int d[V * 2];
bitset<V * 2> f;
vector<int> a[V * 2];
// int length[2];
int length[V * 2];
void generate() {
queue<int> q;
for (int i = 0; i < n * 2; i++) {
if (d[i] == 0) {
q.push(i);
}
}
while (q.empty() == 0) {
int u = q.front(), v = p[u];
q.pop();
f[u] = 1;
d[v] = d[v] - 1;
if (d[v] == 0) {
q.push(v);
}
}
for (int i = 0; i < n * 2; i++) {
if (f[i] == 0) {
vector<int> a;
for (int u = i; f[u] == 0; u = p[u]) {
a.push_back(u);
f[u] = 1;
}
for (auto u : a) {
length[u] = (int) a.size();
}
}
}
}
bitset<V * 2> state;
int dist[V * 2];
void DFS(int u) {
state[u] = 1;
for (auto v : a[u]) {
if (state[v] == 0) {
dist[v] = dist[u] + 1;
DFS(v);
}
}
}
int count(int u, int k) {
state.reset();
fill(dist, dist + n * 2, (int) 1E9);
dist[u] = 0;
DFS(u);
int sum = 0;
for (int i = 0; i < n; i++) {
if (length[u] == 0 && dist[i] == k) {
sum = sum + 1;
}
if (length[u] > 0 && k - dist[i] >= 0 && (k - dist[i]) % length[u] == 0) {
sum = sum + 1;
}
}
return sum;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
n = N;
m = M;
x = P;
fill(t, t + n, m);
for (int i = 0; i < m; i++) {
int u, v;
u = R[i][0];
v = R[i][1];
e[u].push_back({v, i});
e[v].push_back({u, i});
t[u] = min(t[u], i);
t[v] = min(t[v], i);
}
for (int u = 0; u < n; u++) {
int v, i;
tie(v, i) = e[u][0];
if (i != t[v]) {
p[u] = v;
d[v] = d[v] + 1;
a[v].push_back(u);
} else {
p[u] = v + n;
d[v + n] = d[v + n] + 1;
a[v + n].push_back(u);
}
if ((int) e[u].size() > 1) {
tie(v, i) = e[u][1];
}
if (i != t[v]) {
p[u + n] = v;
d[v] = d[v] + 1;
a[v].push_back(u + n);
} else {
p[u + n] = v + n;
d[v + n] = d[v + n] + 1;
a[v + n].push_back(u + n);
}
}
generate();
int q = Q;
for (int i = 0; i < q; i++) {
int k = G[i];
answer(count(x, k) + count(x + n, k));
// cout << count(x, k) + count(x + n, k) << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
11100 KB |
Output is correct |
2 |
Correct |
5 ms |
11100 KB |
Output is correct |
3 |
Correct |
5 ms |
11040 KB |
Output is correct |
4 |
Correct |
4 ms |
11100 KB |
Output is correct |
5 |
Correct |
5 ms |
11100 KB |
Output is correct |
6 |
Correct |
5 ms |
11300 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
5 ms |
11100 KB |
Output is correct |
9 |
Correct |
6 ms |
11352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
11100 KB |
Output is correct |
2 |
Correct |
5 ms |
11100 KB |
Output is correct |
3 |
Correct |
5 ms |
11040 KB |
Output is correct |
4 |
Correct |
4 ms |
11100 KB |
Output is correct |
5 |
Correct |
5 ms |
11100 KB |
Output is correct |
6 |
Correct |
5 ms |
11300 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
5 ms |
11100 KB |
Output is correct |
9 |
Correct |
6 ms |
11352 KB |
Output is correct |
10 |
Correct |
5 ms |
11112 KB |
Output is correct |
11 |
Correct |
12 ms |
14128 KB |
Output is correct |
12 |
Correct |
29 ms |
16180 KB |
Output is correct |
13 |
Correct |
37 ms |
31800 KB |
Output is correct |
14 |
Correct |
70 ms |
27508 KB |
Output is correct |
15 |
Correct |
79 ms |
27972 KB |
Output is correct |
16 |
Correct |
59 ms |
24120 KB |
Output is correct |
17 |
Correct |
59 ms |
22864 KB |
Output is correct |
18 |
Correct |
23 ms |
16220 KB |
Output is correct |
19 |
Correct |
62 ms |
27600 KB |
Output is correct |
20 |
Correct |
74 ms |
27988 KB |
Output is correct |
21 |
Correct |
69 ms |
24092 KB |
Output is correct |
22 |
Correct |
75 ms |
22864 KB |
Output is correct |
23 |
Correct |
69 ms |
29164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
11100 KB |
Output is correct |
2 |
Correct |
5 ms |
11100 KB |
Output is correct |
3 |
Correct |
5 ms |
11040 KB |
Output is correct |
4 |
Correct |
4 ms |
11100 KB |
Output is correct |
5 |
Correct |
5 ms |
11100 KB |
Output is correct |
6 |
Correct |
5 ms |
11300 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
5 ms |
11100 KB |
Output is correct |
9 |
Correct |
6 ms |
11352 KB |
Output is correct |
10 |
Correct |
5 ms |
11112 KB |
Output is correct |
11 |
Correct |
12 ms |
14128 KB |
Output is correct |
12 |
Correct |
29 ms |
16180 KB |
Output is correct |
13 |
Correct |
37 ms |
31800 KB |
Output is correct |
14 |
Correct |
70 ms |
27508 KB |
Output is correct |
15 |
Correct |
79 ms |
27972 KB |
Output is correct |
16 |
Correct |
59 ms |
24120 KB |
Output is correct |
17 |
Correct |
59 ms |
22864 KB |
Output is correct |
18 |
Correct |
23 ms |
16220 KB |
Output is correct |
19 |
Correct |
62 ms |
27600 KB |
Output is correct |
20 |
Correct |
74 ms |
27988 KB |
Output is correct |
21 |
Correct |
69 ms |
24092 KB |
Output is correct |
22 |
Correct |
75 ms |
22864 KB |
Output is correct |
23 |
Correct |
69 ms |
29164 KB |
Output is correct |
24 |
Correct |
8 ms |
11096 KB |
Output is correct |
25 |
Correct |
207 ms |
14132 KB |
Output is correct |
26 |
Correct |
291 ms |
16220 KB |
Output is correct |
27 |
Execution timed out |
5060 ms |
31796 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |