#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
using namespace std;
vector < int > ed[150005];
vector < pair < int , int > > r[2][150005];
vector < int > p[2];
int cycle1=-1,cycle2=-1;
void dfs(pair<int,int> vn,int rn,pair<int,int> &orv){
//printf("vn = %d %d rn=%d orv= %d %d\n",vn.st,vn.nd,rn,orv.st,orv.nd);
if(vn==orv&&rn!=0)
if(orv.nd==0){cycle1=rn;return;}
else {cycle2=rn;return;}
if(vn.nd==0)
if(orv.nd==0)p[0][vn.st]=rn;
else p[1][vn.st]=rn;
if(vn.nd==0)
for(int i=0;i<r[0][vn.st].size();i++)
dfs(r[0][vn.st][i],rn+1,orv);
else
for(int i=0;i<r[1][vn.st].size();i++)
dfs(r[1][vn.st][i],rn+1,orv);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
for(int i=0;i<M;i++){ed[R[i][0]].pb(R[i][1]);ed[R[i][1]].pb(R[i][0]);}
for(int i=0;i<2;i++){p[i].resize(150005);fill(p[i].begin(),p[i].end(),-1);}
for(int i=0;i<N;i++){
if(ed[ed[i][0]][0]!=i) r[0][ed[i][0]].pb(mp(i,0)); // a 0 dan b 0
if(ed[ed[i][0]][0]==i) r[1][ed[i][0]].pb(mp(i,0)); // a 0 dan b 1
if(ed[i].size()>=2){
if(ed[ed[i][1]][0]!=i) r[0][ed[i][1]].pb(mp(i,1)); // a 1 den b 0
else if(ed[ed[i][1]][0]==i) r[1][ed[i][1]].pb(mp(i,1)); // a 1 den b 1
}
else{
if(ed[ed[i][0]][0]!=i) r[0][ed[i][0]].pb(mp(i,1)); // a 0 dan b 0
if(ed[ed[i][0]][0]==i) r[1][ed[i][0]].pb(mp(i,1)); // a 0 dan b 1
}
}
pair<int,int>orv1=mp(P,0),orv2=mp(P,1);
dfs(orv1,0,orv1);
dfs(orv2,0,orv2);
for(int i=0;i<Q;i++){
int ans=0;
for(int j=0;j<N;j++){
//if(p[0][j]==G[i])ans++;
if(p[0][j]!=-1 and cycle1!=-1 and (G[i]-p[0][j])%cycle1==0 and G[i]-p[0][j]>=0)ans++;
else if(p[0][j]!=-1 and cycle1==-1 and p[0][j]==G[i])ans++;
//if(p[1][j]==G[i])ans++;
if(p[1][j]!=-1 and cycle2!=-1 and (G[i]-p[1][j])%cycle2==0 and G[i]-p[1][j]>=0)ans++;
else if(p[1][j]!=-1 and cycle2==-1 and p[1][j]==G[i])ans++;
}
answer(ans);
}
}
Compilation message
garden.cpp: In function 'void dfs(std::pair<int, int>, int, std::pair<int, int>&)':
garden.cpp:16:4: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if(vn==orv&&rn!=0)
^
garden.cpp:19:4: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if(vn.nd==0)
^
garden.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<r[0][vn.st].size();i++)
~^~~~~~~~~~~~~~~~~~~
garden.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<r[1][vn.st].size();i++)
~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
12252 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
13 ms |
12024 KB |
Output is correct |
6 |
Correct |
13 ms |
12268 KB |
Output is correct |
7 |
Correct |
13 ms |
12024 KB |
Output is correct |
8 |
Correct |
14 ms |
12144 KB |
Output is correct |
9 |
Correct |
16 ms |
12408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
12252 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
13 ms |
12024 KB |
Output is correct |
6 |
Correct |
13 ms |
12268 KB |
Output is correct |
7 |
Correct |
13 ms |
12024 KB |
Output is correct |
8 |
Correct |
14 ms |
12144 KB |
Output is correct |
9 |
Correct |
16 ms |
12408 KB |
Output is correct |
10 |
Correct |
13 ms |
12132 KB |
Output is correct |
11 |
Correct |
26 ms |
14368 KB |
Output is correct |
12 |
Correct |
45 ms |
15756 KB |
Output is correct |
13 |
Correct |
71 ms |
29216 KB |
Output is correct |
14 |
Correct |
161 ms |
23368 KB |
Output is correct |
15 |
Correct |
198 ms |
23804 KB |
Output is correct |
16 |
Correct |
151 ms |
21156 KB |
Output is correct |
17 |
Correct |
135 ms |
20104 KB |
Output is correct |
18 |
Correct |
48 ms |
15800 KB |
Output is correct |
19 |
Correct |
159 ms |
23728 KB |
Output is correct |
20 |
Correct |
191 ms |
23928 KB |
Output is correct |
21 |
Correct |
161 ms |
20684 KB |
Output is correct |
22 |
Correct |
139 ms |
20080 KB |
Output is correct |
23 |
Correct |
170 ms |
24796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
12252 KB |
Output is correct |
2 |
Correct |
13 ms |
12152 KB |
Output is correct |
3 |
Correct |
13 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
13 ms |
12024 KB |
Output is correct |
6 |
Correct |
13 ms |
12268 KB |
Output is correct |
7 |
Correct |
13 ms |
12024 KB |
Output is correct |
8 |
Correct |
14 ms |
12144 KB |
Output is correct |
9 |
Correct |
16 ms |
12408 KB |
Output is correct |
10 |
Correct |
13 ms |
12132 KB |
Output is correct |
11 |
Correct |
26 ms |
14368 KB |
Output is correct |
12 |
Correct |
45 ms |
15756 KB |
Output is correct |
13 |
Correct |
71 ms |
29216 KB |
Output is correct |
14 |
Correct |
161 ms |
23368 KB |
Output is correct |
15 |
Correct |
198 ms |
23804 KB |
Output is correct |
16 |
Correct |
151 ms |
21156 KB |
Output is correct |
17 |
Correct |
135 ms |
20104 KB |
Output is correct |
18 |
Correct |
48 ms |
15800 KB |
Output is correct |
19 |
Correct |
159 ms |
23728 KB |
Output is correct |
20 |
Correct |
191 ms |
23928 KB |
Output is correct |
21 |
Correct |
161 ms |
20684 KB |
Output is correct |
22 |
Correct |
139 ms |
20080 KB |
Output is correct |
23 |
Correct |
170 ms |
24796 KB |
Output is correct |
24 |
Correct |
14 ms |
12124 KB |
Output is correct |
25 |
Correct |
103 ms |
14328 KB |
Output is correct |
26 |
Correct |
145 ms |
15948 KB |
Output is correct |
27 |
Correct |
1502 ms |
29192 KB |
Output is correct |
28 |
Correct |
1240 ms |
23288 KB |
Output is correct |
29 |
Correct |
1876 ms |
23496 KB |
Output is correct |
30 |
Correct |
1063 ms |
20680 KB |
Output is correct |
31 |
Correct |
1016 ms |
19604 KB |
Output is correct |
32 |
Correct |
161 ms |
15380 KB |
Output is correct |
33 |
Correct |
1248 ms |
22888 KB |
Output is correct |
34 |
Correct |
1805 ms |
23112 KB |
Output is correct |
35 |
Correct |
1049 ms |
20180 KB |
Output is correct |
36 |
Correct |
1557 ms |
19312 KB |
Output is correct |
37 |
Correct |
888 ms |
23952 KB |
Output is correct |
38 |
Correct |
2574 ms |
34468 KB |
Output is correct |