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;
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
vector<int> vc[200200], ans(Q, 0), dis(N, 0), vis(N, 0);
queue<pair<int, int>> q;
for(int i = 0; i < M; ++i) vc[R[i][0]].push_back(R[i][1]), vc[R[i][1]].push_back(R[i][0]);
q.emplace(P, 0);
vis[P] = 1;
while(!q.empty()){
int u = q.front().first, w = q.front().second; q.pop();
for(auto v:vc[u]){
if(vis[v]) continue;
dis[v] = w + 1;
vis[v] = 1;
q.emplace(v, w + 1);
}
}
int n = -1;
for(int i = 0; i < Q; ++i) n = max(n, G[i]);
vector<int> dp(n+1, 0);
dp[0] = 1;
for(int i = 1; i <= n; ++i){
for(int j = 0; j < N; ++j){
if(i - 2*dp[j] >= 0) dp[i] += dp[i - 2*dp[j]];
}
}
for(int i = 0; i < Q; ++i) answer(dp[G[i]]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |