Submission #29501

# Submission time Handle Problem Language Result Execution time Memory
29501 2017-07-19T14:13:07 Z osmanorhan Tropical Garden (IOI11_garden) C++14
100 / 100
1642 ms 32204 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

const int maxn = 150020;

typedef pair<int,int> ii;

vector<int> best[maxn];
vector<ii> w[maxn][2];

int mark[maxn], went[maxn], cycle;
int ans[maxn], p, L;

void dfs( int n, int s, int deep ) {
    if( n == p && s == L && deep != 0 ) {
        cycle = deep;
        return;
    }

    if( s == 0 ) mark[n] = deep, went[n] = 1;

    for(int i=0;i<w[n][s].size();i++)
        dfs( w[n][s][i].first, w[n][s][i].second, deep+1 );
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
    p = P;

    for(int i=0;i<M;i++) {
        int u = R[i][0];
        int v = R[i][1];
        if( best[v].size() <= 1 ) best[v].pb( u );
        if( best[u].size() <= 1 ) best[u].pb( v );
    }
    for(int i=0;i<N;i++)
        if( best[i].size() == 1 ) best[i].pb( best[i][0] );

    for(int i=0;i<N;i++)
        for(int j=0;j<2;j++) {
            int go = best[i][j];
            int s = (best[go][0] == i);
            w[go][s].pb( ii( i, j ) );
        }

    for(int l=0;l<2;l++) {
        for(int i=0;i<N;i++) mark[i] = went[i] = 0;
        cycle = -1;
        L = l;
        dfs( P, l, 0 );

        for(int i=0;i<N;i++) {
            if( !went[i] ) continue;
            for(int j=0;j<Q;j++) {
                if( mark[i] > G[j] ) continue;
                if( cycle == -1 && G[j] == mark[i] ) ans[j]++;
                else if( cycle > 0 && (G[j]-mark[i])%cycle == 0 ) ans[j]++;
            }
        }
    }

    for(int i=0;i<Q;i++)
        answer( ans[i] );

}

Compilation message

garden.cpp: In function 'void dfs(int, int, int)':
garden.cpp:26:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<w[n][s].size();i++)
                 ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 11128 KB Output is correct
2 Correct 12 ms 11076 KB Output is correct
3 Correct 12 ms 11000 KB Output is correct
4 Correct 12 ms 10984 KB Output is correct
5 Correct 12 ms 10872 KB Output is correct
6 Correct 13 ms 11128 KB Output is correct
7 Correct 12 ms 10972 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 14 ms 11136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 11128 KB Output is correct
2 Correct 12 ms 11076 KB Output is correct
3 Correct 12 ms 11000 KB Output is correct
4 Correct 12 ms 10984 KB Output is correct
5 Correct 12 ms 10872 KB Output is correct
6 Correct 13 ms 11128 KB Output is correct
7 Correct 12 ms 10972 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 14 ms 11136 KB Output is correct
10 Correct 12 ms 10872 KB Output is correct
11 Correct 24 ms 13340 KB Output is correct
12 Correct 45 ms 14840 KB Output is correct
13 Correct 65 ms 26532 KB Output is correct
14 Correct 259 ms 23620 KB Output is correct
15 Correct 226 ms 23800 KB Output is correct
16 Correct 160 ms 20524 KB Output is correct
17 Correct 138 ms 19260 KB Output is correct
18 Correct 46 ms 14940 KB Output is correct
19 Correct 190 ms 23648 KB Output is correct
20 Correct 219 ms 23960 KB Output is correct
21 Correct 154 ms 20444 KB Output is correct
22 Correct 148 ms 19280 KB Output is correct
23 Correct 205 ms 24768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 11128 KB Output is correct
2 Correct 12 ms 11076 KB Output is correct
3 Correct 12 ms 11000 KB Output is correct
4 Correct 12 ms 10984 KB Output is correct
5 Correct 12 ms 10872 KB Output is correct
6 Correct 13 ms 11128 KB Output is correct
7 Correct 12 ms 10972 KB Output is correct
8 Correct 12 ms 11000 KB Output is correct
9 Correct 14 ms 11136 KB Output is correct
10 Correct 12 ms 10872 KB Output is correct
11 Correct 24 ms 13340 KB Output is correct
12 Correct 45 ms 14840 KB Output is correct
13 Correct 65 ms 26532 KB Output is correct
14 Correct 259 ms 23620 KB Output is correct
15 Correct 226 ms 23800 KB Output is correct
16 Correct 160 ms 20524 KB Output is correct
17 Correct 138 ms 19260 KB Output is correct
18 Correct 46 ms 14940 KB Output is correct
19 Correct 190 ms 23648 KB Output is correct
20 Correct 219 ms 23960 KB Output is correct
21 Correct 154 ms 20444 KB Output is correct
22 Correct 148 ms 19280 KB Output is correct
23 Correct 205 ms 24768 KB Output is correct
24 Correct 13 ms 10872 KB Output is correct
25 Correct 47 ms 13372 KB Output is correct
26 Correct 58 ms 14856 KB Output is correct
27 Correct 1580 ms 26620 KB Output is correct
28 Correct 452 ms 23644 KB Output is correct
29 Correct 1642 ms 23864 KB Output is correct
30 Correct 966 ms 19624 KB Output is correct
31 Correct 930 ms 18256 KB Output is correct
32 Correct 53 ms 14372 KB Output is correct
33 Correct 457 ms 22616 KB Output is correct
34 Correct 1638 ms 22808 KB Output is correct
35 Correct 975 ms 19552 KB Output is correct
36 Correct 981 ms 18272 KB Output is correct
37 Correct 325 ms 23900 KB Output is correct
38 Correct 1494 ms 32204 KB Output is correct