#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
#define B 150000
using namespace std;
vector<int> v(2*B);
vector<vector<int>> adj(B),T(B*2);
vector<bool> vis(2*B);
int sz=0;
bool findcyclic(int x,int st){
if(vis[x]&&x==st)return 1;
else if(vis[x])return 0;
vis[x]=1;
sz++;
bool ret=findcyclic(v[x],st);
vis[x]=0;
return ret;
}
vector<int>P1,P2;
void bfs(int x,vector<int>& S){
queue<pair<int,int>> q;
vector<bool> vv(B*2);
q.push({x,0});
while(!q.empty()){
int node=q.front().first,we=q.front().second;
q.pop();
if(vv[node])continue;
vv[node]=1;
if(node<B)S.push_back(we);
for(auto i:T[node]){
if(!vv[i])q.push({i,we+1});
}
}
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
for(int i=0;i<M;i++){
adj[R[i][0]].push_back(R[i][1]);
adj[R[i][1]].push_back(R[i][0]);
}
for(int i=0;i<N;i++){
if(i==adj[adj[i][0]][0])v[i]=adj[i][0]+B;
else v[i]=adj[i][0];
if(adj[i].size()>=2){
if(adj[adj[i][1]][0]==i)v[B+i]=adj[i][1]+B;
else v[B+i]=adj[i][1];
}
else v[B+i]=v[i];
}
int sz1=0,sz2=0;
if(findcyclic(P,P)){
sz1=sz;
}
sz=0;
if(findcyclic(P+B,P+B)){
sz2=sz;
}
sz=0;
for(int i=0;i<N;i++){
T[v[i]].push_back(i);
T[v[i+B]].push_back(i+B);
}
bfs(P,P1);
bfs(P+B,P2);
for(int j=0;j<Q;j++){
int y0=0;
for(auto i:P1){
if(i>G[j])break;
if(sz1==0){
if(G[j]==i)y0++;
}else{
if((G[j]-i)%sz1==0)y0++;
}
}
for(auto i:P2){
if(i>G[j])break;
if(sz2==0){
if(G[j]==i)y0++;
}else{
if((G[j]-i)%sz2==0)y0++;
}
}
answer(y0);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12112 KB |
Output is correct |
2 |
Correct |
6 ms |
12368 KB |
Output is correct |
3 |
Correct |
5 ms |
12368 KB |
Output is correct |
4 |
Correct |
4 ms |
12112 KB |
Output is correct |
5 |
Correct |
4 ms |
12108 KB |
Output is correct |
6 |
Correct |
5 ms |
12368 KB |
Output is correct |
7 |
Correct |
5 ms |
12112 KB |
Output is correct |
8 |
Correct |
5 ms |
12112 KB |
Output is correct |
9 |
Correct |
5 ms |
12368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12112 KB |
Output is correct |
2 |
Correct |
6 ms |
12368 KB |
Output is correct |
3 |
Correct |
5 ms |
12368 KB |
Output is correct |
4 |
Correct |
4 ms |
12112 KB |
Output is correct |
5 |
Correct |
4 ms |
12108 KB |
Output is correct |
6 |
Correct |
5 ms |
12368 KB |
Output is correct |
7 |
Correct |
5 ms |
12112 KB |
Output is correct |
8 |
Correct |
5 ms |
12112 KB |
Output is correct |
9 |
Correct |
5 ms |
12368 KB |
Output is correct |
10 |
Correct |
5 ms |
12112 KB |
Output is correct |
11 |
Correct |
12 ms |
16096 KB |
Output is correct |
12 |
Correct |
20 ms |
16976 KB |
Output is correct |
13 |
Correct |
44 ms |
28864 KB |
Output is correct |
14 |
Correct |
61 ms |
23628 KB |
Output is correct |
15 |
Correct |
70 ms |
24616 KB |
Output is correct |
16 |
Correct |
51 ms |
21716 KB |
Output is correct |
17 |
Correct |
45 ms |
20676 KB |
Output is correct |
18 |
Correct |
20 ms |
16976 KB |
Output is correct |
19 |
Correct |
52 ms |
23464 KB |
Output is correct |
20 |
Correct |
68 ms |
24064 KB |
Output is correct |
21 |
Correct |
47 ms |
21576 KB |
Output is correct |
22 |
Correct |
44 ms |
20552 KB |
Output is correct |
23 |
Correct |
60 ms |
24392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12112 KB |
Output is correct |
2 |
Correct |
6 ms |
12368 KB |
Output is correct |
3 |
Correct |
5 ms |
12368 KB |
Output is correct |
4 |
Correct |
4 ms |
12112 KB |
Output is correct |
5 |
Correct |
4 ms |
12108 KB |
Output is correct |
6 |
Correct |
5 ms |
12368 KB |
Output is correct |
7 |
Correct |
5 ms |
12112 KB |
Output is correct |
8 |
Correct |
5 ms |
12112 KB |
Output is correct |
9 |
Correct |
5 ms |
12368 KB |
Output is correct |
10 |
Correct |
5 ms |
12112 KB |
Output is correct |
11 |
Correct |
12 ms |
16096 KB |
Output is correct |
12 |
Correct |
20 ms |
16976 KB |
Output is correct |
13 |
Correct |
44 ms |
28864 KB |
Output is correct |
14 |
Correct |
61 ms |
23628 KB |
Output is correct |
15 |
Correct |
70 ms |
24616 KB |
Output is correct |
16 |
Correct |
51 ms |
21716 KB |
Output is correct |
17 |
Correct |
45 ms |
20676 KB |
Output is correct |
18 |
Correct |
20 ms |
16976 KB |
Output is correct |
19 |
Correct |
52 ms |
23464 KB |
Output is correct |
20 |
Correct |
68 ms |
24064 KB |
Output is correct |
21 |
Correct |
47 ms |
21576 KB |
Output is correct |
22 |
Correct |
44 ms |
20552 KB |
Output is correct |
23 |
Correct |
60 ms |
24392 KB |
Output is correct |
24 |
Correct |
5 ms |
12112 KB |
Output is correct |
25 |
Correct |
21 ms |
15952 KB |
Output is correct |
26 |
Correct |
25 ms |
16976 KB |
Output is correct |
27 |
Correct |
720 ms |
28832 KB |
Output is correct |
28 |
Correct |
159 ms |
25052 KB |
Output is correct |
29 |
Correct |
609 ms |
25884 KB |
Output is correct |
30 |
Correct |
411 ms |
22736 KB |
Output is correct |
31 |
Correct |
370 ms |
22212 KB |
Output is correct |
32 |
Correct |
22 ms |
17488 KB |
Output is correct |
33 |
Correct |
157 ms |
23632 KB |
Output is correct |
34 |
Correct |
609 ms |
26148 KB |
Output is correct |
35 |
Correct |
412 ms |
22468 KB |
Output is correct |
36 |
Correct |
400 ms |
22144 KB |
Output is correct |
37 |
Correct |
123 ms |
25928 KB |
Output is correct |
38 |
Correct |
675 ms |
36108 KB |
Output is correct |