This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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] <= last[g[node][1].second])){
for(pii &a:g[g[node][0].first]){
last[a.second] = 0;
}
last[g[node][0].second] = ++t;
return dfs(g[node][0].first, left - 1);
}
else{
for(pii &a:g[g[node][1].first]){
last[a.second] = 0;
}
last[g[node][1].second] = ++t;
return dfs(g[node][1].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);
ans += dfs(i, G[j]);
}
answer(ans);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |