#include "garden.h"
#include "gardenlib.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int NN = 5e5 + 5;
int f[NN];
int deg[NN];
int Deg[NN];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
vector < pii > e;
int n = N;
for (int i = 0;i < n + n;++i)
f[i] = -1;
for (int i = 0;i < M;++i) {
int u = R[i][0];
int v = R[i][1];
++Deg[u];
++Deg[v];
smin(Deg[u],2);
smin(Deg[v],2);
}
for (int i = 0;i < M;++i) {
int u = R[i][0];
int v = R[i][1];
++deg[u];
++deg[v];
smin(deg[u],2);
smin(deg[v],2);
for (int cs = 0;cs < 2;++cs) {
if (deg[u] == 1) {
if (deg[v] == Deg[v])
f[u * 2] = v * 2;
else
f[u * 2] = v * 2 + 1;
}
else
if (deg[u] == 2) {
if (deg[v] == Deg[v])
f[u * 2 + 1] = v * 2;
else
f[u * 2 + 1] = v * 2 + 1;
}
swap(u,v);
}
}
//for (int i = 0;i < n + n;++i)
// cerr << i << ' ' << f[i] << '\n';
auto go = [&](int cnt,int cur) {
while (cnt > 0 && cur >= 0) {
--cnt;
cur = f[cur];
}
return cur != -1 && (cur / 2) == P;
};
for (int i = 0;i < Q;++i) {
int ans = 0;
for (int j = 0;j < n + n;j += 2) {
ans += go(G[i],j) || go(G[i],j + 1);
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
424 KB |
Output is correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
424 KB |
Output is correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
424 KB |
Output is correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |