#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
bool comp(pii a, pii b){
return a.second > b.second;
}
const int MAX = 2e5 + 5;
vector<pii> g[MAX];
int last[MAX];
int t = 1;
int f = 0;
bool dfs(int node, int left){
if(left == 0){
return node == f;
}
if(g[node].size() == 1){
last[g[node][0].second] = ++t;
return dfs(g[node][0].first, left - 1);
}
else{
if(last[g[node][0].second] > last[g[node][1].second]){
last[g[node][1].second] = ++t;
return dfs(g[node][1].first, left - 1);
}
else{
last[g[node][0].second] = ++t;
return dfs(g[node][0].first, left - 1);
}
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
f = P;
for (int i = 0; i < M; i++)
{
g[R[i][0]].push_back({R[i][1], M - i - 1});
g[R[i][1]].push_back({R[i][0], M - i - 1});
}
for (int i = 0; i < N; i++)
{
sort(g[i].begin(), g[i].end(), comp);
}
for (int j = 0; j < Q; j++)
{
int ans = 0;
for (int i = 0; i < N; i++)
{
t = 0;
fill(last, last + M, 0);
if(dfs(i, G[j])){
ans++;
}
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5076 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |