#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
using namespace std;
void dfs(int st, int dep, vector<int>(&g)[], int f[], int t, int n){
f[st]=dep;
for(int i : g[st]){
if(i==t){
f[t]=dep+1;
continue;
}
if(i==st+n||i==st-n){
dfs(i,dep,g,f,t, n);
continue;
}
dfs(i,dep+1,g,f,t, n);
}
}
void count_routes(int n, int m, int t, int edges[][2], int q, int G[])
{
vector<int>g[2*n];
int cn[n];
fill(cn,cn+n,0);
for(int i = 0;i<m;i++){
int u1=edges[i][0];
int v1=edges[i][1];
if(cn[u1]>cn[v1]){
swap(u1,v1);
}
int u2 = u1+n;
int v2 = v1+n;
if(cn[u1]==0&&cn[v1]==0){
g[v2].push_back(u1);
g[u2].push_back(v1);
}
else if(cn[u1]==0&&cn[v1]==1){
g[v1].push_back(u1);
g[u2].push_back(v2);
}
else if(cn[u1]==0&&cn[v1]>1){
g[v1].push_back(u1);
}
else if(cn[u1]==1&&cn[v1]==1){
g[v1].push_back(u2);
g[u1].push_back(v2);
}
else if(cn[u1]==1&&cn[v1]>1){
g[v1].push_back(u2);
}
cn[u1]++;
cn[v1]++;
}
for(int i = 0;i<n;i++){
if(cn[i]==1){
g[i].push_back(i+n);
}
} int f1[2*n];
fill(f1,f1+2*n,-1);
queue<pair<int,int>>qu;
qu.push({t,0});
while(!qu.empty()){
pair<int,int>p=qu.front();
qu.pop();
f1[p.first]=p.second;
//cout << p.first << " " << f1[p.first] << "\n";
if(p.first==t&&p.second!=0)
continue;
for(int v : g[p.first]){
if(v==p.first+n||v==p.first-n){
qu.push({v,p.second});
continue;
}
qu.push({v,p.second+1});
}
}
//dfs(t,0,g,f1,t,-1, n);
int f2[2*n];
fill(f2,f2+2*n,-1);
qu.push({n+t,0});
while(!qu.empty()){
pair<int,int>p=qu.front();
qu.pop();
f2[p.first]=p.second;
//cout << p.first << " " << f2[p.first] << "\n";
if(p.first==n+t&&p.second!=0)
continue;
for(int v : g[p.first]){
if(v==p.first+n||v==p.first-n){
qu.push({v,p.second});
continue;
}
qu.push({v,p.second+1});
}
}
//dfs(t+n,0,g,f2,t+n,-1, n);
auto t1 = [&] (int u, int D) -> bool{
if(f1[u]==-1) return 0;
if(f1[u]==D) return 1;
if(f1[u]>D) return 0;
return f1[t] && (D-f1[u])%f1[t]==0;
};
auto t2 = [&] (int u, int D) -> bool{
if(f2[u]==-1) return 0;
if(f2[u]==D) return 1;
if(f2[u]>D) return 0;
return f2[t+n] && (D-f2[u])%f2[t+n]==0;
};
for(int i = 0;i<q;i++){
int ans = 0;
for(int j = 0;j<n;j++){
//cout << f1[j] << " " << f2[j] << "\n";
if(t1(j,G[i])||t2(j,G[i])){
ans++;
}
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
3784 KB |
Output is correct |
12 |
Correct |
13 ms |
5444 KB |
Output is correct |
13 |
Correct |
25 ms |
13040 KB |
Output is correct |
14 |
Correct |
43 ms |
18428 KB |
Output is correct |
15 |
Correct |
55 ms |
18652 KB |
Output is correct |
16 |
Correct |
39 ms |
12884 KB |
Output is correct |
17 |
Correct |
35 ms |
11356 KB |
Output is correct |
18 |
Correct |
13 ms |
5468 KB |
Output is correct |
19 |
Correct |
42 ms |
18524 KB |
Output is correct |
20 |
Correct |
52 ms |
18660 KB |
Output is correct |
21 |
Correct |
37 ms |
12744 KB |
Output is correct |
22 |
Correct |
36 ms |
11344 KB |
Output is correct |
23 |
Correct |
44 ms |
20304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
3784 KB |
Output is correct |
12 |
Correct |
13 ms |
5444 KB |
Output is correct |
13 |
Correct |
25 ms |
13040 KB |
Output is correct |
14 |
Correct |
43 ms |
18428 KB |
Output is correct |
15 |
Correct |
55 ms |
18652 KB |
Output is correct |
16 |
Correct |
39 ms |
12884 KB |
Output is correct |
17 |
Correct |
35 ms |
11356 KB |
Output is correct |
18 |
Correct |
13 ms |
5468 KB |
Output is correct |
19 |
Correct |
42 ms |
18524 KB |
Output is correct |
20 |
Correct |
52 ms |
18660 KB |
Output is correct |
21 |
Correct |
37 ms |
12744 KB |
Output is correct |
22 |
Correct |
36 ms |
11344 KB |
Output is correct |
23 |
Correct |
44 ms |
20304 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
63 ms |
3420 KB |
Output is correct |
26 |
Correct |
99 ms |
5432 KB |
Output is correct |
27 |
Correct |
700 ms |
13108 KB |
Output is correct |
28 |
Correct |
695 ms |
18512 KB |
Output is correct |
29 |
Correct |
780 ms |
18884 KB |
Output is correct |
30 |
Correct |
397 ms |
13020 KB |
Output is correct |
31 |
Correct |
434 ms |
11180 KB |
Output is correct |
32 |
Correct |
105 ms |
5572 KB |
Output is correct |
33 |
Correct |
713 ms |
18724 KB |
Output is correct |
34 |
Correct |
766 ms |
18772 KB |
Output is correct |
35 |
Correct |
434 ms |
12884 KB |
Output is correct |
36 |
Correct |
797 ms |
11232 KB |
Output is correct |
37 |
Correct |
528 ms |
20308 KB |
Output is correct |
38 |
Correct |
1252 ms |
23100 KB |
Output is correct |