#include "garden.h"
#include "gardenlib.h"
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const int inf = 0x3f3f3f3f;
const int mxn = 300000;
int a[mxn][2];
int d[mxn], p[mxn], vis[mxn];
vector<int> g[mxn];
int ans[mxn];
void dfs(int c){
vis[c] = 1;
for(int i : g[c]){
if(vis[i]) continue;
d[i] = d[c] + 1;
dfs(i);
}
}
void count_routes(int n, int m, int k, int e[][2], int q, int qr[]){
memset(a, inf, sizeof(a));
memset(p, -1, sizeof(p));
for(int i = 0; i < m; i++)
for(int j = 0; j < 2; j++){
int x = e[i][j];
a[x][1] = min(a[x][1], i);
sort(a[x], a[x] + 2);
}
for(int i = 0; i < n; i++){
if(a[i][0] == inf){
p[i] = i;
g[i].push_back(i);
}
}
for(int i = 0; i < m; i++)
for(int j = 0; j < 2; j++){
int x = e[i][j], y = e[i][!j];
for(int l = 0; l < 2; l++){
if(a[x][l] == i){
int u = (a[y][0] == i && a[y][1] != inf) * n + y, v = l * n + x;
p[v] = u;
g[u].push_back(v);
}
}
}
for(int t = 0; t < 2; t++){
memset(d, inf, sizeof(d));
memset(vis, 0, sizeof(vis));
int x = t * n + k, y, l;
for(y = x; ~y && !vis[y]; y = p[y]) vis[y] = 1;
for(int i = p[x]; i != y; i = p[i]) vis[i] = 0;
d[x] = 0;
dfs(x);
if(x == y) l = d[p[x]] + 1;
for(int i = 0; i < n; i++)
for(int j = 0; j < q; j++){
if(x != y) ans[j] += d[i] == qr[j];
else ans[j] += d[i] <= qr[j] && (d[i] % l) == (qr[j] % l);
}
}
for(int i = 0; i < q; i++) answer(ans[i]);
}
Compilation message
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:73:57: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
else ans[j] += d[i] <= qr[j] && (d[i] % l) == (qr[j] % l);
~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13312 KB |
Output is correct |
2 |
Correct |
9 ms |
13312 KB |
Output is correct |
3 |
Correct |
9 ms |
13312 KB |
Output is correct |
4 |
Correct |
9 ms |
13312 KB |
Output is correct |
5 |
Correct |
9 ms |
13312 KB |
Output is correct |
6 |
Correct |
10 ms |
13440 KB |
Output is correct |
7 |
Correct |
9 ms |
13304 KB |
Output is correct |
8 |
Correct |
9 ms |
13312 KB |
Output is correct |
9 |
Correct |
11 ms |
13456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13312 KB |
Output is correct |
2 |
Correct |
9 ms |
13312 KB |
Output is correct |
3 |
Correct |
9 ms |
13312 KB |
Output is correct |
4 |
Correct |
9 ms |
13312 KB |
Output is correct |
5 |
Correct |
9 ms |
13312 KB |
Output is correct |
6 |
Correct |
10 ms |
13440 KB |
Output is correct |
7 |
Correct |
9 ms |
13304 KB |
Output is correct |
8 |
Correct |
9 ms |
13312 KB |
Output is correct |
9 |
Correct |
11 ms |
13456 KB |
Output is correct |
10 |
Correct |
9 ms |
13312 KB |
Output is correct |
11 |
Correct |
18 ms |
14592 KB |
Output is correct |
12 |
Correct |
32 ms |
15420 KB |
Output is correct |
13 |
Correct |
54 ms |
24952 KB |
Output is correct |
14 |
Correct |
80 ms |
19192 KB |
Output is correct |
15 |
Correct |
108 ms |
19320 KB |
Output is correct |
16 |
Correct |
86 ms |
18168 KB |
Output is correct |
17 |
Correct |
81 ms |
17528 KB |
Output is correct |
18 |
Correct |
30 ms |
15360 KB |
Output is correct |
19 |
Correct |
84 ms |
19164 KB |
Output is correct |
20 |
Correct |
114 ms |
19320 KB |
Output is correct |
21 |
Correct |
94 ms |
18168 KB |
Output is correct |
22 |
Correct |
98 ms |
17528 KB |
Output is correct |
23 |
Correct |
86 ms |
19832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
13312 KB |
Output is correct |
2 |
Correct |
9 ms |
13312 KB |
Output is correct |
3 |
Correct |
9 ms |
13312 KB |
Output is correct |
4 |
Correct |
9 ms |
13312 KB |
Output is correct |
5 |
Correct |
9 ms |
13312 KB |
Output is correct |
6 |
Correct |
10 ms |
13440 KB |
Output is correct |
7 |
Correct |
9 ms |
13304 KB |
Output is correct |
8 |
Correct |
9 ms |
13312 KB |
Output is correct |
9 |
Correct |
11 ms |
13456 KB |
Output is correct |
10 |
Correct |
9 ms |
13312 KB |
Output is correct |
11 |
Correct |
18 ms |
14592 KB |
Output is correct |
12 |
Correct |
32 ms |
15420 KB |
Output is correct |
13 |
Correct |
54 ms |
24952 KB |
Output is correct |
14 |
Correct |
80 ms |
19192 KB |
Output is correct |
15 |
Correct |
108 ms |
19320 KB |
Output is correct |
16 |
Correct |
86 ms |
18168 KB |
Output is correct |
17 |
Correct |
81 ms |
17528 KB |
Output is correct |
18 |
Correct |
30 ms |
15360 KB |
Output is correct |
19 |
Correct |
84 ms |
19164 KB |
Output is correct |
20 |
Correct |
114 ms |
19320 KB |
Output is correct |
21 |
Correct |
94 ms |
18168 KB |
Output is correct |
22 |
Correct |
98 ms |
17528 KB |
Output is correct |
23 |
Correct |
86 ms |
19832 KB |
Output is correct |
24 |
Correct |
10 ms |
13312 KB |
Output is correct |
25 |
Correct |
200 ms |
14720 KB |
Output is correct |
26 |
Correct |
282 ms |
15352 KB |
Output is correct |
27 |
Correct |
4300 ms |
25080 KB |
Output is correct |
28 |
Correct |
1546 ms |
19332 KB |
Output is correct |
29 |
Correct |
4569 ms |
19388 KB |
Output is correct |
30 |
Correct |
2821 ms |
18188 KB |
Output is correct |
31 |
Correct |
2520 ms |
17676 KB |
Output is correct |
32 |
Correct |
201 ms |
15352 KB |
Output is correct |
33 |
Correct |
1542 ms |
19320 KB |
Output is correct |
34 |
Correct |
4565 ms |
19368 KB |
Output is correct |
35 |
Correct |
2934 ms |
18168 KB |
Output is correct |
36 |
Correct |
2532 ms |
17656 KB |
Output is correct |
37 |
Correct |
1325 ms |
19704 KB |
Output is correct |
38 |
Correct |
4315 ms |
28964 KB |
Output is correct |