이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |