Submission #121521

# Submission time Handle Problem Language Result Execution time Memory
121521 2019-06-26T16:29:39 Z baqargam Tropical Garden (IOI11_garden) C++14
0 / 100
12 ms 11116 KB
#include<bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"

using namespace std;

int a,k,n,m,q,p,v1[300005],sz,sz1,sz2,st,ch,res,d[2][300005],c;
bool fx[300005];
bool fx1[300005];
vector<pair<int,int> >v[150005];
vector<int>rv[300005];

void cch(int x,int dis,int st){
    for(vector<int> :: iterator it=rv[x].begin();it!=rv[x].end();it++){
        if(*it==st) {sz=dis+1;return;}//if(x>86000)cout<<x<<" "<<*it<<endl;
        cch(*it,dis+1,st);
    }
}

void dfs(int x,int dis,int st){
    d[c][x]=dis;
    fx1[x]=1;
   // cout<<x<<" "<<c<<" ";
    for(vector<int> :: iterator it=rv[x].begin();it!=rv[x].end();it++){
        if(!fx1[*it])
        dfs(*it,dis+1,st);
    }
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    int n=N,m=M,p=P,i;
    for(i=0;i<m;i++){///grafi1
        v[R[i][0]].push_back({i,R[i][1]});
        v[R[i][1]].push_back({i,R[i][0]});
    }
    for(i=0;i<n;i++){
        sort(v[i].begin(),v[i].end());
    }
    for(i=0;i<n;i++){///grafi2
        if(v[i].size()==1)
        {
            int to=v[i][0].second;
            int val=v[i][0].first;
            if(v[to][0].first==val)
                v1[(i<<1)^1]=(to<<1)^1;
            else
                v1[(i<<1)^1]=(to<<1);

            if(v[to][0].first==val)
                v1[(i<<1)]=(to<<1)^1;
            else
                v1[(i<<1)]=(to<<1);
        }
        else
        {
            int to=v[i][0].second;
            int val=v[i][0].first;
//            cout<<i<<" "<<to<<" "<<val<<" "<<v[to][0].first<<endl;
            if(v[to][0].first==val)
                v1[(i<<1)]=(to<<1)^1;
            else
                v1[(i<<1)]=(to<<1);

            to=v[i][1].second;
            val=v[i][1].first;
//            cout<<i<<" "<<to<<" "<<val<<" "<<v[to][0].first<<endl;
            if(v[to][0].first==val)
                v1[(i<<1)^1]=(to<<1)^1;
            else
                v1[(i<<1)^1]=(to<<1);

        }
    }

    for(i=0;i<2*n;i++){
        rv[v1[i]].push_back(i);
    }

    sz=1000000003;cch(2*p,0,2*p);sz1=sz;//cout<<34;
    sz=1000000003;cch(2*p+1,0,2*p+1);sz2=sz;

    c=0;memset (fx1,0,n<<1);dfs((p<<1),0,(p<<1));
    c=1;memset (fx1,0,n<<1);dfs((p<<1)^1,0,(p<<1)^1);

    for(i=0; i<Q; i++)
    {
        //cout<<i<<endl;
        k=G[i];
        res=0;
        for(int x=0;x<n<<1;x+=2){
            if(((k-d[0][x])%sz==0 && k>=d[0][x]) ||
               ((k-d[1][x])%sz==0 && k>=d[1][x]))
                res++;
        }
        answer(res);
    }

}

# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 11116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 11116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 11116 KB Output isn't correct
2 Halted 0 ms 0 KB -