This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** made by amunduzbaev **/
#include "garden.h"
#include "gardenlib.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Pi acos(-1);
#define mod 1e9+7
#define inf 1e18
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
const int NN = 2e5+5;
vii edges[NN];
int bup[NN][40];
ll cnt;
void count_routes(int n, int m, int p, int R[][2], int q, int kk[]){
for(int i=0; i<m; i++){
int a = R[i][0], b = R[i][1];
if(sz(edges[a]) < 2) edges[a].pb(b);
if(sz(edges[b]) < 2) edges[b].pb(a);
}
for(int i=0;i<n;i++){
for(int j=0;j<sz(edges[i]);j++){
int to = edges[i][j];
if(edges[to][0] == i && sz(edges[to]) > 1) bup[i + j * n][0] = to+n;
else bup[i + j * n][0] = to;
}
}
for(int j=1;j<31;j++){
for(int i=0;i<n*2;i++){
bup[i][j] = bup[bup[i][j-1]][j-1];
}
}
for(int i=0;i<q;i++){
int K, cur, cnt = 0;
for(int j=0;j<n;j++){
K = kk[i], cur = j;
for(int l=30;l>=0;l--){
if(K >= (1<<l)){
K -= (1 << l);
cur = bup[cur][l];
}
}
cnt += (cur == p || cur == p + n);
}
answer(cnt);
}
}
/*
6 6 0
1 2
0 1
0 3
3 4
4 5
1 5
1
3
2
5 5 2
1 0
1 2
3 2
1 3
4 2
2
3 1
1 2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |