#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
bitset<150005> vis;
vector<pii> Gr[150005];
int k,p,cur[150005],dis;
bool dfs(int u,int f)
{
//cout << u << " ";
++dis;
if(dis==k) return u==p;
if(dis>k) return 0;
if(Gr[u][0].S!=f)
if(dfs(Gr[u][0].F,Gr[u][0].S)==1) return 1;
else return 0;
if(Gr[u].size()>1)
if(dfs(Gr[u][1].F,Gr[u][1].S)==1) return 1;
else return 0;
if(dfs(Gr[u][0].F,Gr[u][0].S)==1) return 1;
return 0;
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
p=P;
for(int i=0;i<M;++i)
Gr[R[i][0]].pb(MP(R[i][1],i)),Gr[R[i][1]].pb(MP(R[i][0],i));
for(int i=0;i<Q;++i)
{
int ans=0;
k=G[i];
for(int j=0;j<N;++j)
dis=-1,/*,cout << j << ": ",*/ans+=dfs(j,-1);//,ET;
answer(ans);
}
}
Compilation message
garden.cpp: In function 'bool dfs(int, int)':
garden.cpp:28:4: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if(Gr[u][0].S!=f)
^
garden.cpp:31:4: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if(Gr[u].size()>1)
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3932 KB |
Output is correct |
2 |
Correct |
6 ms |
3960 KB |
Output is correct |
3 |
Correct |
6 ms |
3932 KB |
Output is correct |
4 |
Correct |
5 ms |
3832 KB |
Output is correct |
5 |
Correct |
5 ms |
3804 KB |
Output is correct |
6 |
Correct |
6 ms |
3960 KB |
Output is correct |
7 |
Correct |
3 ms |
3836 KB |
Output is correct |
8 |
Correct |
6 ms |
4060 KB |
Output is correct |
9 |
Correct |
9 ms |
4088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3932 KB |
Output is correct |
2 |
Correct |
6 ms |
3960 KB |
Output is correct |
3 |
Correct |
6 ms |
3932 KB |
Output is correct |
4 |
Correct |
5 ms |
3832 KB |
Output is correct |
5 |
Correct |
5 ms |
3804 KB |
Output is correct |
6 |
Correct |
6 ms |
3960 KB |
Output is correct |
7 |
Correct |
3 ms |
3836 KB |
Output is correct |
8 |
Correct |
6 ms |
4060 KB |
Output is correct |
9 |
Correct |
9 ms |
4088 KB |
Output is correct |
10 |
Correct |
11 ms |
3832 KB |
Output is correct |
11 |
Execution timed out |
5018 ms |
4856 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3932 KB |
Output is correct |
2 |
Correct |
6 ms |
3960 KB |
Output is correct |
3 |
Correct |
6 ms |
3932 KB |
Output is correct |
4 |
Correct |
5 ms |
3832 KB |
Output is correct |
5 |
Correct |
5 ms |
3804 KB |
Output is correct |
6 |
Correct |
6 ms |
3960 KB |
Output is correct |
7 |
Correct |
3 ms |
3836 KB |
Output is correct |
8 |
Correct |
6 ms |
4060 KB |
Output is correct |
9 |
Correct |
9 ms |
4088 KB |
Output is correct |
10 |
Correct |
11 ms |
3832 KB |
Output is correct |
11 |
Execution timed out |
5018 ms |
4856 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |