#include<fstream>
#include<vector>
#include<cstring>
#include "garden.h"
#include "gardenlib.h"
#define DIM 300005
using namespace std;
static int viz[2][DIM], dist[2][DIM], t[DIM], cic[DIM], nrcic[DIM], pos[DIM], viz2[DIM];
static pair<int, int> p[DIM][2];
static vector<int> v[DIM];
static void dfs(int nod, int t){
viz[t][nod] = 1;
for(int i = 0; i < v[nod].size(); i++){
int vecin = v[nod][i];
if(viz[t][vecin] == 0){
dist[t][vecin] = 1 + dist[t][nod];
dfs(vecin, t);
}
}
}
static void calcp(int i, int x, int y){
if(p[x][0].first == 0){
p[x][0] = make_pair(i, y);
}
else{
if(p[x][1].first == 0){
p[x][1] = make_pair(i, y);
}
}
}
static void calct(int x, pair<int, int> curr){
if(p[ curr.second ][0].first == curr.first && p[ curr.second ][1].first != 0){
t[x] = 2 * curr.second;
}
else{
t[x] = 2 * curr.second - 1;
}
}
void count_routes(int n, int m, int d, int w[][2], int q, int g[]){
int i, x, k, j, sol, ii;
d++;
for(i = 0; i < m; i++){
w[i][0]++;
w[i][1]++;
calcp(i + 1, w[i][0], w[i][1]);
calcp(i + 1, w[i][1], w[i][0]);
}
for(i = 1; i <= n; i++){
calct(2 * i - 1, p[i][0]);
if(p[i][1].first != 0){
calct(2 * i, p[i][1]);
}
else{
t[2 * i] = 2 * i;
}
}
k = 0;
for(i = 1; i <= 2 * n; i++){
v[ t[i] ].push_back(i);
x = i;
while(viz2[x] == 0){
viz2[x] = 1;
pos[x] = i;
x = t[x];
}
if(pos[x] == i){
k++;
while(viz2[x] != 2){
viz2[x] = 2;
cic[x] = k;
nrcic[k]++;
x = t[x];
}
}
}
dfs(2 * d - 1, 0);
dfs(2 * d, 1);
for(i = 0; i < q; i++){
sol = 0;
for(x = 2 * d - 1, ii = 0; ii <= 1; ii++, x++){
for(j = 1; j <= 2 * n; j += 2){
if(cic[x] != 0){
if(viz[ii][j] == 1 && dist[ii][j] <= g[i] && (dist[ii][j] - g[i]) % nrcic[ cic[x] ] == 0){
sol++;
}
}
else{
if(viz[ii][j] == 1 && dist[ii][j] == g[i]){
sol++;
}
}
}
}
answer(sol);
}
}
Compilation message
garden.cpp: In function 'void dfs(int, int)':
garden.cpp:13:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v[nod].size(); i++){
~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7544 KB |
Output is correct |
2 |
Correct |
10 ms |
7544 KB |
Output is correct |
3 |
Correct |
11 ms |
7544 KB |
Output is correct |
4 |
Correct |
9 ms |
7416 KB |
Output is correct |
5 |
Correct |
9 ms |
7416 KB |
Output is correct |
6 |
Correct |
10 ms |
7672 KB |
Output is correct |
7 |
Correct |
9 ms |
7416 KB |
Output is correct |
8 |
Correct |
10 ms |
7544 KB |
Output is correct |
9 |
Correct |
11 ms |
7672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7544 KB |
Output is correct |
2 |
Correct |
10 ms |
7544 KB |
Output is correct |
3 |
Correct |
11 ms |
7544 KB |
Output is correct |
4 |
Correct |
9 ms |
7416 KB |
Output is correct |
5 |
Correct |
9 ms |
7416 KB |
Output is correct |
6 |
Correct |
10 ms |
7672 KB |
Output is correct |
7 |
Correct |
9 ms |
7416 KB |
Output is correct |
8 |
Correct |
10 ms |
7544 KB |
Output is correct |
9 |
Correct |
11 ms |
7672 KB |
Output is correct |
10 |
Correct |
9 ms |
7416 KB |
Output is correct |
11 |
Correct |
20 ms |
10360 KB |
Output is correct |
12 |
Correct |
34 ms |
12280 KB |
Output is correct |
13 |
Correct |
60 ms |
29048 KB |
Output is correct |
14 |
Correct |
121 ms |
24100 KB |
Output is correct |
15 |
Correct |
152 ms |
25720 KB |
Output is correct |
16 |
Correct |
109 ms |
18424 KB |
Output is correct |
17 |
Correct |
100 ms |
17528 KB |
Output is correct |
18 |
Correct |
37 ms |
11768 KB |
Output is correct |
19 |
Correct |
118 ms |
25336 KB |
Output is correct |
20 |
Correct |
153 ms |
25848 KB |
Output is correct |
21 |
Correct |
112 ms |
18272 KB |
Output is correct |
22 |
Correct |
103 ms |
17656 KB |
Output is correct |
23 |
Correct |
124 ms |
25340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7544 KB |
Output is correct |
2 |
Correct |
10 ms |
7544 KB |
Output is correct |
3 |
Correct |
11 ms |
7544 KB |
Output is correct |
4 |
Correct |
9 ms |
7416 KB |
Output is correct |
5 |
Correct |
9 ms |
7416 KB |
Output is correct |
6 |
Correct |
10 ms |
7672 KB |
Output is correct |
7 |
Correct |
9 ms |
7416 KB |
Output is correct |
8 |
Correct |
10 ms |
7544 KB |
Output is correct |
9 |
Correct |
11 ms |
7672 KB |
Output is correct |
10 |
Correct |
9 ms |
7416 KB |
Output is correct |
11 |
Correct |
20 ms |
10360 KB |
Output is correct |
12 |
Correct |
34 ms |
12280 KB |
Output is correct |
13 |
Correct |
60 ms |
29048 KB |
Output is correct |
14 |
Correct |
121 ms |
24100 KB |
Output is correct |
15 |
Correct |
152 ms |
25720 KB |
Output is correct |
16 |
Correct |
109 ms |
18424 KB |
Output is correct |
17 |
Correct |
100 ms |
17528 KB |
Output is correct |
18 |
Correct |
37 ms |
11768 KB |
Output is correct |
19 |
Correct |
118 ms |
25336 KB |
Output is correct |
20 |
Correct |
153 ms |
25848 KB |
Output is correct |
21 |
Correct |
112 ms |
18272 KB |
Output is correct |
22 |
Correct |
103 ms |
17656 KB |
Output is correct |
23 |
Correct |
124 ms |
25340 KB |
Output is correct |
24 |
Correct |
10 ms |
7416 KB |
Output is correct |
25 |
Correct |
156 ms |
10104 KB |
Output is correct |
26 |
Correct |
231 ms |
12024 KB |
Output is correct |
27 |
Correct |
2672 ms |
28284 KB |
Output is correct |
28 |
Correct |
1235 ms |
27512 KB |
Output is correct |
29 |
Correct |
3298 ms |
27768 KB |
Output is correct |
30 |
Correct |
1944 ms |
20292 KB |
Output is correct |
31 |
Correct |
1918 ms |
19448 KB |
Output is correct |
32 |
Correct |
160 ms |
12408 KB |
Output is correct |
33 |
Correct |
1204 ms |
26360 KB |
Output is correct |
34 |
Correct |
3362 ms |
27640 KB |
Output is correct |
35 |
Correct |
2084 ms |
20344 KB |
Output is correct |
36 |
Correct |
2438 ms |
19324 KB |
Output is correct |
37 |
Correct |
1088 ms |
27252 KB |
Output is correct |
38 |
Correct |
2956 ms |
38672 KB |
Output is correct |