#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
int n, m, P, k, ans = 0;
vector<int> adj[150005];
int succ[300005][20];
void calc(int i) {
int l = 0;
int a = i;
while(l < k) {
a = succ[a][0];
l++;
}
//cout << i << " " << p << " " << a << " " << p << endl;
if (a == P || a == P+n) {
ans++;
}
}
void count_routes(int N, int M, int pp, int R[][2], int Q, int G[]) {
n = N, m = M, P = pp;
for (int i = 0; i < m; i++) {
if (adj[R[i][0]].size() < 2) {
adj[R[i][0]].push_back(R[i][1]);
}
if (adj[R[i][1]].size() < 2) {
adj[R[i][1]].push_back(R[i][0]);
}
}
for (int i = 0; i < n; i++) {
if (adj[i].size() == 1) {
if (i == adj[adj[i][0]][0]) {
succ[i][0] = adj[i][0]+n;
} else {
succ[i][0] = adj[i][0];
}
succ[i+n][0] = succ[i][0];
} else {
if (i == adj[adj[i][0]][0]) {
succ[i][0] = adj[i][0]+n;
} else {
succ[i][0] = adj[i][0];
}
if (i == adj[adj[i][1]][0]) {
succ[i+n][0] = adj[i][1]+n;
} else {
succ[i+n][0] = adj[i][1];
}
}
}
for (int j = 0; j < Q; j++) {
k = G[j];
ans = 0;
for (int i = 0; i < n; i++) {
calc(i);
}
answer(ans);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3928 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
3 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
3932 KB |
Output is correct |
5 |
Correct |
2 ms |
4188 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
3 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3928 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
3 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
3932 KB |
Output is correct |
5 |
Correct |
2 ms |
4188 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
3 ms |
4300 KB |
Output is correct |
10 |
Correct |
5 ms |
3932 KB |
Output is correct |
11 |
Execution timed out |
5085 ms |
8612 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3928 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
3 ms |
4188 KB |
Output is correct |
4 |
Correct |
2 ms |
3932 KB |
Output is correct |
5 |
Correct |
2 ms |
4188 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
2 ms |
3932 KB |
Output is correct |
8 |
Correct |
2 ms |
4188 KB |
Output is correct |
9 |
Correct |
3 ms |
4300 KB |
Output is correct |
10 |
Correct |
5 ms |
3932 KB |
Output is correct |
11 |
Execution timed out |
5085 ms |
8612 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |