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 <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
/*****************************************/
//just have to implement
#define pi pair<int,int>
#define pb push_back
#define ll long long
#define f first
#define s second
const int maxn = 2e3 +5;
//int level[maxn];
int graph[maxn][2];
bool follow_path(int n,int p, int k){
//cout << n <<": ";
int prev = -1;
for(int i =0; i<k; i++){
if(graph[n][0]== prev)
{
prev = n;
n = graph[n][1];
}
else{
prev = n;
n = graph[n][0];
}
}
//cout << n <<", "<< p<<", "<<k<<endl;
if(n == p) return 1;
return 0;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
memset(graph, -1, sizeof(graph));
for(int i =0; i<M; i++){
int a = R[i][0];
int b = R[i][1];
if(graph[a][0] == -1){
graph[a][0] = b;
graph[a][1] = b;
}
else if(graph[a][0] == graph[a][1]){
graph[a][1] = b;
}
if(graph[b][0] == -1){
graph[b][0] = a;
graph[b][1] = a;
}
else if(graph[b][0] == graph[b][1]){
graph[b][1] = a;
}
}
/*
for(int i =0; i< N; i++){
cout << i <<" -> "<<graph[i ][0]<<"\n";
cout << i <<"' -> "<<graph[i ][1]<<"\n";
}*/
for(int i =0; i<Q; i++){
ll ans = 0;
for(int j =0; j<N; j++){
ans+=follow_path(j,P, G[i]);
}
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... |