#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 2;
int k, ans, p, cnt[MAXN], used[MAXN], fl;
vector <int> g[MAXN];
void dfs(int v){
if(fl) return ;
if(cnt[v] == k){
fl = 1;
if(v == p)
ans ++;
return ;
}
used[v] = 1;
for(int i = 0; i < g[v].size(); i ++){
int to = g[v][i];
if(used[to]) continue;
cnt[to] = cnt[v] + 1;
dfs(to);
cnt[v] = cnt[to] + 1;
if(cnt[v] == k){
fl = 1;
if(v == p)
ans ++;
return ;
}
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
for(int i = 0; i < M; i ++){
int u = R[i][0], v = R[i][1];
if(g[u].size() < 2)
g[u].push_back(v);
if(g[v].size() < 2)
g[v].push_back(u);
}
p = P;
for(int i = 0; i < Q; i ++){
k = G[i];
ans = 0;
for(int i = 1; i < N; i ++){
memset(cnt, 0, sizeof(cnt));
memset(used, 0, sizeof(used));
fl = 0;
dfs(i);
}
answer(ans);
}
}
Compilation message
garden.cpp: In function 'void dfs(int)':
garden.cpp:21:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < g[v].size(); i ++){
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |