Submission #70930

#TimeUsernameProblemLanguageResultExecution timeMemory
70930aleksamTropical Garden (IOI11_garden)C++14
Compilation error
0 ms0 KiB
using namespace std; vector<int> adj[MAX_N*2]; int best[MAX_N][2]; int dist[2][2*MAX_N]; bool mark[2][2*MAX_N]; int p, cyclen, num; int cnt[2*MAX_N]; int cumcnt[2*MAX_N]; void DFS(int u){ int d=adj[u].size(); for(int i=0; i<d; ++i){ if(!mark[num][adj[u][i]]){ mark[num][adj[u][i]]=1; dist[num][adj[u][i]]=dist[num][u]+1; DFS(adj[u][i]); } if(adj[u][i]==p){ cyclen=dist[num][u]+1; } } } void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){ //u adj cuvamo sva temena koja se ulivaju u i //prvo odredjujemo najlepse putanje svakom temenu for(int i=0; i<N; ++i){ best[i][0]=best[i][1]=-1; } for(int i=0; i<M; ++i){ if(best[R[i][0]][0]==-1){ best[R[i][0]][0]=R[i][1]; } else{ if(best[R[i][0]][1]==-1){ best[R[i][0]][1]=R[i][1]; } } if(best[R[i][1]][0]==-1){ best[R[i][1]][0]=R[i][0]; } else{ if(best[R[i][1]][1]==-1){ best[R[i][1]][1]=R[i][0]; } } } for(int i=0; i<N; ++i){ //Odredjujemo gde ide cvor i if(best[best[i][0]][0]==i && best[best[i][0]][1]!=-1){ adj[best[i][0]+N].push_back(i); } else adj[best[i][0]].push_back(i); if(best[i][1]==-1)continue; if(best[best[i][1]][0]==i && best[best[i][0]][1]!=-1){ adj[best[i][1]+N].push_back(i+N); } else adj[best[i][1]].push_back(i+N); } /*for(int i=0; i<2*N; ++i){ printf("adj[%d]:", i); for(int j=0; j<adj[i].size(); ++j){ printf("%d ", adj[i][j]); } printf("\n"); }*/ mark[0][P]=1; p=P; cyclen=-1; dist[0][P]=0; DFS(P); num=1; mark[1][P+N]=1; p=P+N; dist[1][P+N]=0; DFS(P+N); for(int i=0; i<2*N; ++i){ printf("dist:%d %d\n", dist[0][i], dist[1][i]); if(i<N){ cnt[dist[0][i]]++; cnt[dist[1][i]]++; } } for(int i=0; i<N; ++i){ printf("cnt:%d\n", cnt[i]); } cnt[0]=1; if(cyclen==-1){ for(int i=0; i<Q; ++i){ answer(cnt[G[i]]); //cout<<cnt[G[i]]; } return; } for(int i=0; i<2*N; ++i){ cumcnt[i]=cnt[i]; if(i>=cyclen) cumcnt[i]+=cumcnt[i-cyclen]; } for(int i=0; i<Q; ++i){ if(G[i]>=2*N){ answer(cumcnt[ G[i]%cyclen+2*N-cyclen]); //cout<<cumcnt[ G[i]%cyclen+2*N-cyclen]; } else { answer(cumcnt[G[i]]); //cout<<cumcnt[G[i]]; } } return; }

Compilation message (stderr)

garden.cpp:3:1: error: 'vector' does not name a type
 vector<int> adj[MAX_N*2];
 ^~~~~~
garden.cpp:4:10: error: 'MAX_N' was not declared in this scope
 int best[MAX_N][2];
          ^~~~~
garden.cpp:5:15: error: 'MAX_N' was not declared in this scope
 int dist[2][2*MAX_N];
               ^~~~~
garden.cpp:6:16: error: 'MAX_N' was not declared in this scope
 bool mark[2][2*MAX_N];
                ^~~~~
garden.cpp:8:11: error: 'MAX_N' was not declared in this scope
 int cnt[2*MAX_N];
           ^~~~~
garden.cpp:9:14: error: 'MAX_N' was not declared in this scope
 int cumcnt[2*MAX_N];
              ^~~~~
garden.cpp: In function 'void DFS(int)':
garden.cpp:12:8: error: 'adj' was not declared in this scope
  int d=adj[u].size();
        ^~~
garden.cpp:14:7: error: 'mark' was not declared in this scope
   if(!mark[num][adj[u][i]]){
       ^~~~
garden.cpp:16:4: error: 'dist' was not declared in this scope
    dist[num][adj[u][i]]=dist[num][u]+1;
    ^~~~
garden.cpp:16:4: note: suggested alternative: 'int'
    dist[num][adj[u][i]]=dist[num][u]+1;
    ^~~~
    int
garden.cpp:20:11: error: 'dist' was not declared in this scope
    cyclen=dist[num][u]+1;
           ^~~~
garden.cpp:20:11: note: suggested alternative: 'int'
    cyclen=dist[num][u]+1;
           ^~~~
           int
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:29:3: error: 'best' was not declared in this scope
   best[i][0]=best[i][1]=-1;
   ^~~~
garden.cpp:32:6: error: 'best' was not declared in this scope
   if(best[R[i][0]][0]==-1){
      ^~~~
garden.cpp:40:6: error: 'best' was not declared in this scope
   if(best[R[i][1]][0]==-1){
      ^~~~
garden.cpp:51:6: error: 'best' was not declared in this scope
   if(best[best[i][0]][0]==i && best[best[i][0]][1]!=-1){
      ^~~~
garden.cpp:52:4: error: 'adj' was not declared in this scope
    adj[best[i][0]+N].push_back(i);
    ^~~
garden.cpp:55:4: error: 'adj' was not declared in this scope
    adj[best[i][0]].push_back(i);
    ^~~
garden.cpp:56:6: error: 'best' was not declared in this scope
   if(best[i][1]==-1)continue;
      ^~~~
garden.cpp:57:6: error: 'best' was not declared in this scope
   if(best[best[i][1]][0]==i && best[best[i][0]][1]!=-1){
      ^~~~
garden.cpp:58:4: error: 'adj' was not declared in this scope
    adj[best[i][1]+N].push_back(i+N);
    ^~~
garden.cpp:61:4: error: 'adj' was not declared in this scope
    adj[best[i][1]].push_back(i+N);
    ^~~
garden.cpp:70:2: error: 'mark' was not declared in this scope
  mark[0][P]=1;
  ^~~~
garden.cpp:73:2: error: 'dist' was not declared in this scope
  dist[0][P]=0;
  ^~~~
garden.cpp:73:2: note: suggested alternative: 'int'
  dist[0][P]=0;
  ^~~~
  int
garden.cpp:81:3: error: 'printf' was not declared in this scope
   printf("dist:%d %d\n", dist[0][i], dist[1][i]);
   ^~~~~~
garden.cpp:81:3: note: suggested alternative: 'int'
   printf("dist:%d %d\n", dist[0][i], dist[1][i]);
   ^~~~~~
   int
garden.cpp:84:4: error: 'cnt' was not declared in this scope
    cnt[dist[0][i]]++;
    ^~~
garden.cpp:84:4: note: suggested alternative: 'int'
    cnt[dist[0][i]]++;
    ^~~
    int
garden.cpp:89:22: error: 'cnt' was not declared in this scope
   printf("cnt:%d\n", cnt[i]);
                      ^~~
garden.cpp:89:22: note: suggested alternative: 'int'
   printf("cnt:%d\n", cnt[i]);
                      ^~~
                      int
garden.cpp:89:3: error: 'printf' was not declared in this scope
   printf("cnt:%d\n", cnt[i]);
   ^~~~~~
garden.cpp:89:3: note: suggested alternative: 'int'
   printf("cnt:%d\n", cnt[i]);
   ^~~~~~
   int
garden.cpp:91:2: error: 'cnt' was not declared in this scope
  cnt[0]=1;
  ^~~
garden.cpp:91:2: note: suggested alternative: 'int'
  cnt[0]=1;
  ^~~
  int
garden.cpp:94:4: error: 'answer' was not declared in this scope
    answer(cnt[G[i]]);
    ^~~~~~
garden.cpp:100:3: error: 'cumcnt' was not declared in this scope
   cumcnt[i]=cnt[i];
   ^~~~~~
garden.cpp:106:11: error: 'cumcnt' was not declared in this scope
    answer(cumcnt[ G[i]%cyclen+2*N-cyclen]);
           ^~~~~~
garden.cpp:106:4: error: 'answer' was not declared in this scope
    answer(cumcnt[ G[i]%cyclen+2*N-cyclen]);
    ^~~~~~
garden.cpp:110:11: error: 'cumcnt' was not declared in this scope
    answer(cumcnt[G[i]]);
           ^~~~~~
garden.cpp:110:4: error: 'answer' was not declared in this scope
    answer(cumcnt[G[i]]);
    ^~~~~~