제출 #399010

#제출 시각아이디문제언어결과실행 시간메모리
399010Pichon5열대 식물원 (Tropical Garden) (IOI11_garden)C++17
0 / 100
1 ms844 KiB
#include <bits/stdc++.h> #include "garden.h" #include "gardenlib.h" #define lcm(a,b) (a/__gcd(a,b))*b #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long int #define vi vector<int> #define vll vector<ll> #define pb push_back #define F first #define S second #define mp make_pair using namespace std; const int tam=200000; const int MA=30; int up[tam][MA]; int up2[tam][MA]; int last[tam][MA]; int last2[tam][MA]; void count_routes(int N, int M, int P, int R[][2], int Q, int g[]) { vector<vector<pair<int,int> > > G(N+1); int n=N; for(int i=0;i<M;i++){ int a=R[i][0],b=R[i][1]; G[a].pb({b,i}); G[b].pb({a,i}); } for(int i=0;i<n;i++){ if(G[i].size()<2)G[i].pb(G[i][0]); up[i][0]=G[i][0].F; last[i][0]=G[i][0].S; up2[i][0]=G[i][1].F; last2[i][0]=G[i][1].S; } for(int i=0;i<=30;i++){ for(int l=0;l<n;l++){ int u=up[l][i]; up[l][i+1]=up[u][i]; last[l][i+1]=last[u][i]; if(last[u][0]==last[l][i]){ up[l][i+1]=up2[u][i]; last[l][i+1]=last2[u][i]; } u=up2[l][i]; up2[l][i+1]=up[u][i]; last2[l][i+1]=last[u][i]; if(last2[l][i]==last[u][0]){ up2[l][i+1]=up2[u][i]; last2[l][i+1]=last2[u][i]; } } } int k=g[0]; int res=0; for(int i=0;i<n;i++){ int nodo=i; int ant=-1; for(int l=29;l>=0;l--){ if((k>>l)&1){ if(last[nodo][0]!=ant){ ant=last[nodo][l]; nodo=up[nodo][l]; }else{ ant=last2[nodo][l]; nodo=up2[nodo][l]; } } } if(nodo==P)res++; } answer(res); } /* 5 5 2 1 0 1 2 3 2 1 3 4 2 1 3 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...