#include <bits/stdc++.h>
using namespace std;
#include "garden.h"
#include "gardenlib.h"
const int LIM = 1.5e5, INF = 2e9;
int n, cnt[LIM], c, d[2][LIM*2], p, r[2] = {INF, INF};
vector<int> g[LIM*2];
void dfs(int u, int dist){
d[c][u] = dist;
for(int v : g[u]) if(d[c][v] == INF) dfs(v, dist + 1);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
n = N, p = P;
for(int i=0; i<M; ++i){
for(int j=0; j<2; ++j){
int u = R[i][j], v = R[i][!j];
if(cnt[u] == 0) g[v + (!cnt[v])*n].push_back(u);
if(cnt[u] == 1) g[v + (!cnt[v])*n].push_back(u+n);
if(u == p && cnt[u] < 2) r[cnt[u]] = v + (!cnt[v])*n;
}
for(int j=0; j<2; ++j) ++cnt[R[i][j]];
}
for(int j=0; j<2; ++j) if(r[j] < INF && r[j] >= n && cnt[r[j]-n] < 2) r[j] -= n;
for(int u=0; u<n; ++u) if(cnt[u] < 2)
for(int v : g[u+n]) g[u].push_back(v);
for(c=0; c<2; ++c) fill(d[c], d[c]+2*n, INF);
for(c=0; c<cnt[p]; ++c) dfs(p+c*n, 0);
for(int i=0; i<2; ++i) if(r[i] < INF) r[i] = 1 + d[i][r[i]];
for(int i=0; i<Q; ++i){
int res = 0;
for(int u=0; u<n; ++u){
for(int j=0; j<2; ++j)
if(d[j][u] <= G[i] && (G[i] - d[j][u]) % r[i] == 0) ++res;
}
answer(res);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7444 KB |
Output is correct |
2 |
Correct |
7 ms |
7356 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Incorrect |
5 ms |
7372 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7444 KB |
Output is correct |
2 |
Correct |
7 ms |
7356 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Incorrect |
5 ms |
7372 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7444 KB |
Output is correct |
2 |
Correct |
7 ms |
7356 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Incorrect |
5 ms |
7372 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |