#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define forr(i,A,B) for(int i=A;i<B;++i)
#define space ' '
#define endl '\n'
#define LL long long
using namespace std;
vector <pair<int,int> > adj[10005];
int g,ans,p;
map<string,int> h;
string s="";
void dfs(int x,int y,int k){
if(k==g and x==p){
//cout<<s<<endl;
h[s]=1;
ans++;
return;
}
else if(k>=g) return;
int l=s.size();
forr(i,0,adj[x].size()){
if(adj[x][i].nd==y and adj[x].size()==1){
s+=(char)y;
dfs(y,x,k+1);
break;
}
else if(adj[x][i].nd!=y){
s+=(char)adj[x][i].nd;
dfs(adj[x][i].nd,x,k+1);
break;
}
}
s.resize(l);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
forr(i,0,N){
adj[R[i][0]].pb(mp(i,R[i][1]));
adj[R[i][1]].pb(mp(i,R[i][0]));
}
forr(i,0,N){
sort(adj[R[i][0]].begin(),adj[R[i][0]].end());
sort(adj[R[i][1]].begin(),adj[R[i][1]].end());
}
g=G[0];
p=P;
forr(i,0,N){
dfs(i,i,0);
}
for(int i=0; i<Q; i++){
answer(h.size());
}
}
Compilation message
garden.cpp: In function 'void dfs(int, int, int)':
garden.cpp:9:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define forr(i,A,B) for(int i=A;i<B;++i)
garden.cpp:28:7:
forr(i,0,adj[x].size()){
~~~~~~~~~~~~~~~~~
garden.cpp:28:2: note: in expansion of macro 'forr'
forr(i,0,adj[x].size()){
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
628 KB |
Output is correct |
2 |
Correct |
4 ms |
760 KB |
Output is correct |
3 |
Incorrect |
4 ms |
632 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
628 KB |
Output is correct |
2 |
Correct |
4 ms |
760 KB |
Output is correct |
3 |
Incorrect |
4 ms |
632 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
628 KB |
Output is correct |
2 |
Correct |
4 ms |
760 KB |
Output is correct |
3 |
Incorrect |
4 ms |
632 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |