이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")
const int maxn = 3e5 + 5;
vector<int> graph_shit[maxn+5];
vector<int> graph[maxn+5];
int n, up[maxn][31];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
n = N;
for(int i=0; i<M; i++) {
graph_shit[R[i][0]].push_back(R[i][1]);
graph_shit[R[i][1]].push_back(R[i][0]);
}
for(int i=0; i<N; i++) {
int v = graph_shit[i][0];
if(graph_shit[v][0] == i) graph[i].push_back(v+N);
else graph[i].push_back(v);
}
for(int i=N; i<2*N; i++) {
if(graph_shit[i-N].size() == 1) {
int v = graph_shit[i-N][0];
if(graph_shit[v][0] == i-N) graph[i].push_back(v+N);
else graph[i].push_back(v);
} else {
int v = graph_shit[i-N][1];
if(graph_shit[v][0] == i-N) graph[i].push_back(v+N);
else graph[i].push_back(v);
}
}
for(int i=0; i<2*N; i++) up[i][0] = graph[i].back();
for(int j=1; j<31; j++)
for(int i=0; i<2*N; i++) up[i][j] = up[up[i][j-1]][j-1];
for(int i=0; i<Q; i++) {
int ans=0;
for(int j=0; j<N; j++) {
int curr = j;
for(int k=30; k>=0; k--)
if(G[i] & (1ll << k)) curr = up[curr][k];
if(curr == P || curr == P + N) 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... |