Submission #1022539

# Submission time Handle Problem Language Result Execution time Memory
1022539 2024-07-13T16:49:11 Z socpite Tropical Garden (IOI11_garden) C++14
100 / 100
90 ms 51512 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 3e5+5;

vector<pair<int, int>> g_real[maxn];
vector<int> g[maxn];
vector<int> cyc[maxn];
int depcnt[maxn];

int ans[maxn];
int cycsz;

void dfs(int x, int rt, int dep, int N){
    if(x < N)depcnt[dep]++;
    for(auto v: g[x]){
        if(v == rt)cycsz = dep+1;
        else dfs(v, rt, dep+1, N);
    }
}

void solve(int N, int Q, int G[], int id){
    memset(depcnt, 0, sizeof(depcnt));
    cycsz = 0;
    for(int i = 0; i < maxn; i++)cyc[i].clear();

    dfs(id, id, 0, N);
    if(!cycsz)for(int i = 0; i < Q; i++){if(G[i] < maxn)ans[i] += depcnt[G[i]];}
    else {
        for(int i = 0; i < maxn; i++)while(depcnt[i]--)cyc[i%cycsz].push_back(i);
        for(int i = 0; i < Q; i++)ans[i] += upper_bound(cyc[G[i]%cycsz].begin(), cyc[G[i]%cycsz].end(), G[i]) - cyc[G[i]%cycsz].begin();
    }
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    memset(ans, 0, sizeof(ans));
    for(int i = 0; i < 2*N; i++){
        g[i].clear();
        g_real[i].clear();
    }

    for(int i = 0; i < M; i++){
        g_real[R[i][0]].push_back({R[i][1], i});
        g_real[R[i][1]].push_back({R[i][0], i});
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < min(2, (int)g_real[i].size()); j++){
            int v = g_real[i][j].first, w = g_real[i][j].second;
            if(w == g_real[v][0].second && g_real[v].size() > 1){
                g[v+N].push_back(i + N*j);
            }
            else {
                g[v].push_back(i + N*j);
            }
        }
    }
    
    solve(N, Q, G, P);
    if(g_real[P].size() > 1)solve(N, Q, G, P+N);
    for(int i = 0; i < Q; i++)answer(ans[i]);
}


# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 14 ms 23896 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23864 KB Output is correct
6 Correct 12 ms 24152 KB Output is correct
7 Correct 13 ms 23896 KB Output is correct
8 Correct 12 ms 23896 KB Output is correct
9 Correct 13 ms 24180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 14 ms 23896 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23864 KB Output is correct
6 Correct 12 ms 24152 KB Output is correct
7 Correct 13 ms 23896 KB Output is correct
8 Correct 12 ms 23896 KB Output is correct
9 Correct 13 ms 24180 KB Output is correct
10 Correct 11 ms 23948 KB Output is correct
11 Correct 16 ms 25708 KB Output is correct
12 Correct 42 ms 27256 KB Output is correct
13 Correct 49 ms 43152 KB Output is correct
14 Correct 68 ms 34604 KB Output is correct
15 Correct 74 ms 35404 KB Output is correct
16 Correct 90 ms 33188 KB Output is correct
17 Correct 58 ms 32124 KB Output is correct
18 Correct 26 ms 27856 KB Output is correct
19 Correct 63 ms 36180 KB Output is correct
20 Correct 71 ms 37200 KB Output is correct
21 Correct 71 ms 34388 KB Output is correct
22 Correct 59 ms 33616 KB Output is correct
23 Correct 68 ms 37208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 14 ms 23896 KB Output is correct
3 Correct 11 ms 23900 KB Output is correct
4 Correct 11 ms 23900 KB Output is correct
5 Correct 11 ms 23864 KB Output is correct
6 Correct 12 ms 24152 KB Output is correct
7 Correct 13 ms 23896 KB Output is correct
8 Correct 12 ms 23896 KB Output is correct
9 Correct 13 ms 24180 KB Output is correct
10 Correct 11 ms 23948 KB Output is correct
11 Correct 16 ms 25708 KB Output is correct
12 Correct 42 ms 27256 KB Output is correct
13 Correct 49 ms 43152 KB Output is correct
14 Correct 68 ms 34604 KB Output is correct
15 Correct 74 ms 35404 KB Output is correct
16 Correct 90 ms 33188 KB Output is correct
17 Correct 58 ms 32124 KB Output is correct
18 Correct 26 ms 27856 KB Output is correct
19 Correct 63 ms 36180 KB Output is correct
20 Correct 71 ms 37200 KB Output is correct
21 Correct 71 ms 34388 KB Output is correct
22 Correct 59 ms 33616 KB Output is correct
23 Correct 68 ms 37208 KB Output is correct
24 Correct 12 ms 23900 KB Output is correct
25 Correct 18 ms 26204 KB Output is correct
26 Correct 28 ms 27728 KB Output is correct
27 Correct 45 ms 44108 KB Output is correct
28 Correct 66 ms 36432 KB Output is correct
29 Correct 82 ms 37204 KB Output is correct
30 Correct 65 ms 34820 KB Output is correct
31 Correct 58 ms 33616 KB Output is correct
32 Correct 30 ms 27748 KB Output is correct
33 Correct 69 ms 36436 KB Output is correct
34 Correct 87 ms 37260 KB Output is correct
35 Correct 68 ms 34656 KB Output is correct
36 Correct 66 ms 33784 KB Output is correct
37 Correct 68 ms 37460 KB Output is correct
38 Correct 89 ms 51512 KB Output is correct