This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
int n, m; n = N, m = M;
vector<pair<int, int>> vec[n];
int mn[n] = {};
for(int i=1; i<=m; i++){
int a, b; a = R[i-1][0], b = R[i-1][1];
vec[a].pb({b, i}); vec[b].pb({a, i});
if(mn[a] == 0) mn[a] = i;
if(mn[b] == 0) mn[b] = i;
}
int to[2*n] = {};
for(int a=0; a<n; a++){
auto [b, i] = vec[a][0];
if(mn[b] == i) to[a] = n+b;
else to[a] = b;
if(sz(vec[a]) >= 2){
auto [c, j] = vec[a][1];
if(mn[c] == j) to[n+a] = n+c;
else to[n+a] = c;
}
else{
if(mn[b] == i) to[n+a] = n+b;
else to[n+a] = b;
}
}
int p = P;
int q = Q;
for(int i=0; i<q; i++){
int k = G[i];
int ans = 0;
for(int a=0; a<n; a++){
int x = a;
while(k--){
x = to[x];
}
if(x == p or x == n+p) ans++;
}
answer(ans);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |