Submission #399014

# Submission time Handle Problem Language Result Execution time Memory
399014 2021-05-05T03:54:44 Z Pichon5 Tropical Garden (IOI11_garden) C++17
69 / 100
323 ms 83116 KB
#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];
vector<pair<int,int> > G[tam];
void count_routes(int N, int M, int P, int R[][2], int Q, int g[])
{
    int n=N;
    for(int i=0;i<M;i++){
        int a=R[i][0],b=R[i][1];
        if(G[a].size()<2)G[a].pb({b,i});
        if(G[b].size()<2)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=1;i<MA;i++){
        for(int nodo=0;nodo<n;nodo++){
            int mid=up[nodo][i-1];
            up[nodo][i]=up[mid][i-1];
            last[nodo][i]=last[mid][i-1];
            if(last[mid][0]==last[nodo][i-1]){
                up[nodo][i]=up2[mid][i-1];
                last[nodo][i]=last2[mid][i-1];
            }
            mid=up2[nodo][i-1];
            up2[nodo][i]=up[mid][i-1];
            last2[nodo][i]=last[mid][i-1];
            if(last2[nodo][i-1]==last[mid][0]){
                up2[nodo][i]=up2[mid][i-1];
                last2[nodo][i]=last2[mid][i-1];
            }
        }
    }
    int k=g[0];
    int res=0;
    for(int i=0;i<n;i++){
        int nodo=i;
        int ant=-1;
        for(int l=MA;l>=0;l--){
            if((1<<l)&k){
                if(ant!=last[nodo][0]){
                    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 time Memory Grader output
1 Correct 4 ms 5324 KB Output is correct
2 Correct 4 ms 5452 KB Output is correct
3 Correct 4 ms 5452 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 5452 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 4 ms 5452 KB Output is correct
9 Correct 6 ms 5568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5324 KB Output is correct
2 Correct 4 ms 5452 KB Output is correct
3 Correct 4 ms 5452 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 5452 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 4 ms 5452 KB Output is correct
9 Correct 6 ms 5568 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 39 ms 16440 KB Output is correct
12 Correct 76 ms 24264 KB Output is correct
13 Correct 216 ms 48276 KB Output is correct
14 Correct 230 ms 75332 KB Output is correct
15 Correct 230 ms 76208 KB Output is correct
16 Correct 191 ms 53576 KB Output is correct
17 Correct 143 ms 45964 KB Output is correct
18 Correct 71 ms 24732 KB Output is correct
19 Correct 232 ms 75380 KB Output is correct
20 Correct 230 ms 76228 KB Output is correct
21 Correct 188 ms 53456 KB Output is correct
22 Correct 147 ms 45892 KB Output is correct
23 Correct 323 ms 83116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5324 KB Output is correct
2 Correct 4 ms 5452 KB Output is correct
3 Correct 4 ms 5452 KB Output is correct
4 Correct 3 ms 5068 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 4 ms 5452 KB Output is correct
7 Correct 3 ms 5068 KB Output is correct
8 Correct 4 ms 5452 KB Output is correct
9 Correct 6 ms 5568 KB Output is correct
10 Correct 3 ms 5068 KB Output is correct
11 Correct 39 ms 16440 KB Output is correct
12 Correct 76 ms 24264 KB Output is correct
13 Correct 216 ms 48276 KB Output is correct
14 Correct 230 ms 75332 KB Output is correct
15 Correct 230 ms 76208 KB Output is correct
16 Correct 191 ms 53576 KB Output is correct
17 Correct 143 ms 45964 KB Output is correct
18 Correct 71 ms 24732 KB Output is correct
19 Correct 232 ms 75380 KB Output is correct
20 Correct 230 ms 76228 KB Output is correct
21 Correct 188 ms 53456 KB Output is correct
22 Correct 147 ms 45892 KB Output is correct
23 Correct 323 ms 83116 KB Output is correct
24 Incorrect 4 ms 5068 KB Output isn't correct
25 Halted 0 ms 0 KB -