Submission #1092946

# Submission time Handle Problem Language Result Execution time Memory
1092946 2024-09-25T13:27:10 Z Aviansh Tropical Garden (IOI11_garden) C++17
49 / 100
5000 ms 5980 KB
#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"

using namespace std;

void dfs(int st, int dep, vector<int>(&g)[], int f[], bool vis[], int t, int p, int n){
    vis[st]=1;
    //cout << "visiting: " << st << endl;
    f[st]=dep;
    for(int i : g[st]){
        if(i==t){
            f[t]=dep+1;
        }
        if(vis[i])
            continue;
        if(i==st+n||i==st-n){
            dfs(i,dep,g,f,vis,t, st, n);
            continue;
        }
        dfs(i,dep+1,g,f,vis,t, st, n);
    }
}

void count_routes(int n, int m, int t, int edges[][2], int q, int G[])
{
    vector<int>g[2*n];
    int cn[n];
    fill(cn,cn+n,0);
    for(int i = 0;i<m;i++){
        int u1=edges[i][0];
        int v1=edges[i][1];
        if(cn[u1]>cn[v1]){
            swap(u1,v1);
        }
        int u2 = u1+n;
        int v2 = v1+n;
        if(cn[u1]==0&&cn[v1]==0){
            g[v2].push_back(u1);
            g[u2].push_back(v1);
        }
        else if(cn[u1]==0&&cn[v1]==1){
            g[v1].push_back(u1);
            g[u2].push_back(v2);
        }
        else if(cn[u1]==0&&cn[v1]>1){
            g[v1].push_back(u1);
        }
        else if(cn[u1]==1&&cn[v1]==1){
            g[v1].push_back(u2);
            g[u1].push_back(v2);
        }
        else if(cn[u1]==1&&cn[v1]>1){
            g[v1].push_back(u2);
        }
        cn[u1]++;
        cn[v1]++;
    }
    for(int i = 0;i<n;i++){
        if(cn[i]==1){
            g[i].push_back(i+n);
        }
    }
    vector<int>rg[2*n];
    for(int i = 0;i<2*n;i++){
        for (int v : g[i]){
            rg[v].push_back(i);
        }
    }
    int f1[2*n];
    fill(f1,f1+2*n,-1);
    bool vis[2*n];
    fill(vis,vis+2*n,0);
    dfs(t,0,g,f1,vis,t,-1, n);
    int f2[2*n];
    fill(f2,f2+2*n,-1);
    fill(vis,vis+2*n,0);
    dfs(t+n,0,g,f2,vis,t+n,-1, n);
    for(int i = 0;i<q;i++){
        int k = G[i];
        int ans = 0;
        for(int j = 0;j<n;j++){
            int a = j;
            for(int l = 0;l<k;l++){
                assert(rg[a].size()==1);
                if(rg[a][0]==a-n){
                    l--;
                }
                a=rg[a][0];
            }
            if(a==t||a==t+n){
                ans++;
            }
        }
        answer(ans);
    }
    return;
    for(int i = 0;i<q;i++){
        int ans = 0;
        for(int j = 0;j<n;j++){
            if(f1[j]==G[i]||(f1[t]!=0&&f1[j]!=-1&&f1[j]<=G[i]&&f1[j]%f1[t]==G[i]%f1[t])){
                ans++;
            }
            else if(f2[j]==G[i]||(f2[t+n]!=0&&f2[j]!=-1&&f2[j]<=G[i]&&f2[j]%f2[t+n]==G[i]%f2[t+n])){
                ans++;
            }
        }
        answer(ans);
    }
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Execution timed out 5065 ms 5980 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Execution timed out 5065 ms 5980 KB Time limit exceeded
12 Halted 0 ms 0 KB -