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>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
const int N = 1002;;
int p;
int best[N][2];
int k;
int dfs(int node , int cnt , int pre){
if(cnt == k){
if(p == node)return 1;
return 0;
}
int next;
if(pre == 0){
next = best[node][0];
}
else next = best[node][1];
if(best[next][0] == node)return dfs(best[node][pre] , cnt + 1 , 1);
return dfs(best[node][pre] , cnt + 1 , 0);
}
void count_routes(int n, int m, int p1, int r[][2], int q, int g[]){
p = p1;
k = g[0];
vector<int> lol[n + 5];
for(int i = 0; i < m; i++){
lol[r[i][0]].pb(r[i][1]);
lol[r[i][1]].pb(r[i][0]);
}
for(int i = 0; i < n; i++){
best[i][0] = lol[i][0];
if(lol[i].size() > 1)best[i][1] = lol[i][1];
else best[i][1] = best[i][0];
}
int ans = 0;
for(int i = 0; i < n; i++){
ans += dfs(i , 0 , 0);
}
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... |