#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<pair<int, int>> vc[200200];
void dfs(int u, int k, int P, int par){
if(k == 0){
if(u == P) ans++;
return;
}
if(vc[u].size() == 1) dfs(vc[u][0].second, k - 1, P, u);
else{
for(auto x:vc[u]){
int w = x.first, v = x.second;
if(v == par) continue;
dfs(v, k - 1, P, u);
break;
}
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
for(int i = 0; i < M; ++i) vc[R[i][0]].emplace_back(i, R[i][1]), vc[R[i][1]].emplace_back(i, R[i][0]);
for(int i = 0; i < N; ++i) sort(vc[i].begin(), vc[i].end());
for(int i = 0; i < N; ++i) dfs(i, G[0], P, -1);
answer(ans);
}
Compilation message
garden.cpp: In function 'void dfs(int, int, int, int)':
garden.cpp:18:17: warning: unused variable 'w' [-Wunused-variable]
18 | int w = x.first, v = x.second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
Output is correct |
2 |
Correct |
2 ms |
6736 KB |
Output is correct |
3 |
Correct |
2 ms |
6736 KB |
Output is correct |
4 |
Correct |
2 ms |
6736 KB |
Output is correct |
5 |
Correct |
2 ms |
6736 KB |
Output is correct |
6 |
Correct |
3 ms |
6736 KB |
Output is correct |
7 |
Correct |
2 ms |
6736 KB |
Output is correct |
8 |
Correct |
3 ms |
6736 KB |
Output is correct |
9 |
Correct |
4 ms |
6992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
Output is correct |
2 |
Correct |
2 ms |
6736 KB |
Output is correct |
3 |
Correct |
2 ms |
6736 KB |
Output is correct |
4 |
Correct |
2 ms |
6736 KB |
Output is correct |
5 |
Correct |
2 ms |
6736 KB |
Output is correct |
6 |
Correct |
3 ms |
6736 KB |
Output is correct |
7 |
Correct |
2 ms |
6736 KB |
Output is correct |
8 |
Correct |
3 ms |
6736 KB |
Output is correct |
9 |
Correct |
4 ms |
6992 KB |
Output is correct |
10 |
Correct |
6 ms |
6736 KB |
Output is correct |
11 |
Execution timed out |
5071 ms |
7504 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
Output is correct |
2 |
Correct |
2 ms |
6736 KB |
Output is correct |
3 |
Correct |
2 ms |
6736 KB |
Output is correct |
4 |
Correct |
2 ms |
6736 KB |
Output is correct |
5 |
Correct |
2 ms |
6736 KB |
Output is correct |
6 |
Correct |
3 ms |
6736 KB |
Output is correct |
7 |
Correct |
2 ms |
6736 KB |
Output is correct |
8 |
Correct |
3 ms |
6736 KB |
Output is correct |
9 |
Correct |
4 ms |
6992 KB |
Output is correct |
10 |
Correct |
6 ms |
6736 KB |
Output is correct |
11 |
Execution timed out |
5071 ms |
7504 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |