//In the name of God
#include "garden.h"
#include "gardenlib.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll maxn = 5e5 + 100;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll pw(ll a, ll b){
ll c = 1;
while(b){
if(b & 1) c = c * a % mod;
a = a * a % mod;
b >>= 1;
}
return c;
}
int n, a[maxn], dis[maxn];
int cnt[2][maxn], dor[2];
bool vis[maxn];
vector<int> g[maxn], gp[maxn];
void dfs(int v){
vis[v] = 1;
for(int u : gp[v]){
if(vis[u]) continue;
dis[u] = dis[v] + 1;
dfs(u);
}
return;
}
void Do(int x, int f){
memset(dis, -1, sizeof dis);
memset(vis, 0, sizeof vis);
dis[x] = 0;
dfs(x);
for(int i = 0; i < (n << 1); i += 2){
if(~dis[i]) cnt[f][dis[i]]++;
}
dor[f] = -1;
if(dis[a[x]] == -1) return;
int t = dis[a[x]] + 1;
dor[f] = t;
for(int i = t; i < maxn; i++){
cnt[f][i] += cnt[f][i - t];
}
return;
}
void count_routes(int N, int m, int p, int R[][2], int Q, int G[]){
n = N;
for(int i = 0; i < m; i++){
int v = R[i][0], u = R[i][1];
g[v].pb(u);
g[u].pb(v);
}
for(int i = 0; i < n; i++){
int v = g[i][0];
if(g[v][0] == i) a[i << 1] = (v << 1) | 1;
else a[i << 1] = v << 1;
if(Sz(g[i]) == 1){
a[i << 1 | 1] = a[i << 1];
continue;
}
v = g[i][1];
if(g[v][0] == i) a[i << 1 | 1] = (v << 1) | 1;
else a[i << 1 | 1] = v << 1;
}
for(int i = 0; i < (n << 1); i++){
gp[a[i]].pb(i);
}
Do(p << 1, 0);
Do(p << 1 | 1, 1);
for(int i = 0; i < Q; i++){
int x = G[i];
int ans = 0;
if(dor[0] == -1){
if(x < maxn) ans += cnt[0][x];
}
else{
while(x >= maxn) x -= dor[0];
ans += cnt[0][x];
}
x = G[i];
if(dor[1] == -1){
if(x < maxn) ans += cnt[1][x];
}
else{
while(x >= maxn) x -= dor[1];
ans += cnt[1][x];
}
answer(ans);
}
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
30276 KB |
Output is correct |
2 |
Correct |
19 ms |
30208 KB |
Output is correct |
3 |
Correct |
20 ms |
30208 KB |
Output is correct |
4 |
Correct |
18 ms |
28116 KB |
Output is correct |
5 |
Correct |
18 ms |
28212 KB |
Output is correct |
6 |
Correct |
19 ms |
30288 KB |
Output is correct |
7 |
Correct |
17 ms |
30164 KB |
Output is correct |
8 |
Correct |
18 ms |
30152 KB |
Output is correct |
9 |
Correct |
20 ms |
30420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
30276 KB |
Output is correct |
2 |
Correct |
19 ms |
30208 KB |
Output is correct |
3 |
Correct |
20 ms |
30208 KB |
Output is correct |
4 |
Correct |
18 ms |
28116 KB |
Output is correct |
5 |
Correct |
18 ms |
28212 KB |
Output is correct |
6 |
Correct |
19 ms |
30288 KB |
Output is correct |
7 |
Correct |
17 ms |
30164 KB |
Output is correct |
8 |
Correct |
18 ms |
30152 KB |
Output is correct |
9 |
Correct |
20 ms |
30420 KB |
Output is correct |
10 |
Correct |
18 ms |
30088 KB |
Output is correct |
11 |
Correct |
25 ms |
32196 KB |
Output is correct |
12 |
Correct |
38 ms |
33436 KB |
Output is correct |
13 |
Correct |
60 ms |
43532 KB |
Output is correct |
14 |
Correct |
187 ms |
41268 KB |
Output is correct |
15 |
Correct |
167 ms |
41484 KB |
Output is correct |
16 |
Correct |
141 ms |
38448 KB |
Output is correct |
17 |
Correct |
159 ms |
35528 KB |
Output is correct |
18 |
Correct |
39 ms |
29520 KB |
Output is correct |
19 |
Correct |
183 ms |
41260 KB |
Output is correct |
20 |
Correct |
226 ms |
41460 KB |
Output is correct |
21 |
Correct |
107 ms |
36520 KB |
Output is correct |
22 |
Correct |
164 ms |
37432 KB |
Output is correct |
23 |
Correct |
116 ms |
42444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
30276 KB |
Output is correct |
2 |
Correct |
19 ms |
30208 KB |
Output is correct |
3 |
Correct |
20 ms |
30208 KB |
Output is correct |
4 |
Correct |
18 ms |
28116 KB |
Output is correct |
5 |
Correct |
18 ms |
28212 KB |
Output is correct |
6 |
Correct |
19 ms |
30288 KB |
Output is correct |
7 |
Correct |
17 ms |
30164 KB |
Output is correct |
8 |
Correct |
18 ms |
30152 KB |
Output is correct |
9 |
Correct |
20 ms |
30420 KB |
Output is correct |
10 |
Correct |
18 ms |
30088 KB |
Output is correct |
11 |
Correct |
25 ms |
32196 KB |
Output is correct |
12 |
Correct |
38 ms |
33436 KB |
Output is correct |
13 |
Correct |
60 ms |
43532 KB |
Output is correct |
14 |
Correct |
187 ms |
41268 KB |
Output is correct |
15 |
Correct |
167 ms |
41484 KB |
Output is correct |
16 |
Correct |
141 ms |
38448 KB |
Output is correct |
17 |
Correct |
159 ms |
35528 KB |
Output is correct |
18 |
Correct |
39 ms |
29520 KB |
Output is correct |
19 |
Correct |
183 ms |
41260 KB |
Output is correct |
20 |
Correct |
226 ms |
41460 KB |
Output is correct |
21 |
Correct |
107 ms |
36520 KB |
Output is correct |
22 |
Correct |
164 ms |
37432 KB |
Output is correct |
23 |
Correct |
116 ms |
42444 KB |
Output is correct |
24 |
Correct |
27 ms |
30132 KB |
Output is correct |
25 |
Correct |
30 ms |
32256 KB |
Output is correct |
26 |
Correct |
53 ms |
33612 KB |
Output is correct |
27 |
Correct |
72 ms |
43616 KB |
Output is correct |
28 |
Execution timed out |
5074 ms |
41360 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |