Submission #229680

# Submission time Handle Problem Language Result Execution time Memory
229680 2020-05-05T21:39:21 Z achibasadzishvili Tropical Garden (IOI11_garden) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#define ll int
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,m,p,len[300005],o,raod,fix[300005],cik[300005],k,ye;
vector<ll>t[300005],rev[300005];
ll v[300005];
void dfs(ll x,ll dep,ll e,ll hav,ll z){
    if(fix[x])return;
    if(cik[x])hav = 1,z = len[cik[x]];
    if(dep == e || (hav && dep <= e && ((e - dep) % z) == 0))
        raod += (x <= n);
    fix[x] = 1;
    for(int i=0; i<rev[x].size(); i++)
        dfs(rev[x][i] , dep + 1 , e , hav , z);
}
int main(){
    scanf("%d %d %d",&n,&m,&p);
    p++;
    
    for(int i=1; i<=m; i++){
        ll x,y;
        scanf("%d %d",&x,&y);
        x++;
        y++;
        if((int)t[x].size() < 2)t[x].pb(y);
        if((int)t[y].size() < 2)t[y].pb(x);
    }
    
    for(int x=1; x<=n; x++){
        v[x] = t[x][0];
        if(t[t[x][0]][0] == x){
            v[x] = t[x][0] + n;
        }
        if(t[x].size() == 1){
            v[x + n] = v[x];
            continue;
        }
        v[x + n] = t[x][1];
        if(t[t[x][1]][0] == x)v[x + n] = t[x][1] + n;
    }
    for(int i=1; i<=2 * n; i++){
        rev[v[i]].pb(i);
    }
    
    for(int i=1; i<=2*n; i++){
        ll st = i,pu = i,oof=0;
        while(1){
            if(fix[st] == i){
                pu = st;
                break;
            }
            if(fix[st] && fix[st] != i){
                oof = 1;
                break;
            }
            fix[st] = i;
            st = v[st];
        }
        if(oof)continue;
        st = pu;
        ll o = 0;
        while(!o || st != pu){
            len[i]++;
           // cout << st << " ";
            o = 1;
            cik[st] = i;
            st = v[st];
        }
        //cout << '\n';
    }
    ll q;
    
    scanf("%d" , &q);
    
    while(q--){
        for(int i=1; i<=2 * n; i++)
            fix[i] = 0;
        scanf("%d",&k);
        raod = 0;
        ye = 0;
        dfs(p , 0 , k , 0 , 0);
        for(int i=1; i<=2 * n; i++)
            fix[i] = 0;
        dfs(p + n , 0 , k , 0 , 0);
        printf("%d " , raod);
    }
    
    
    return 0;
}

Compilation message

garden.cpp: In function 'void dfs(int, int, int, int, int)':
garden.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<rev[x].size(); i++)
                  ~^~~~~~~~~~~~~~
garden.cpp: In function 'int main()':
garden.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&n,&m,&p);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
garden.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
garden.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d" , &q);
     ~~~~~^~~~~~~~~~~
garden.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&k);
         ~~~~~^~~~~~~~~
/tmp/ccsMFTCS.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cclGIgqL.o:garden.cpp:(.text.startup+0x0): first defined here
/tmp/ccsMFTCS.o: In function `main':
grader.cpp:(.text.startup+0x38): undefined reference to `count_routes(int, int, int, int (*) [2], int, int*)'
collect2: error: ld returned 1 exit status