Submission #1075926

#TimeUsernameProblemLanguageResultExecution timeMemory
1075926antonCop and Robber (BOI14_coprobber)C++17
16 / 100
50 ms2072 KiB
#include "coprobber.h"
#include<bits/stdc++.h>

using namespace std;

vector<vector<int>> ch;
bool B[MAX_N][MAX_N];
int N;
void dfs(int u, int a){
    for(int i = 0; i<N; i++){
        if(i!=a){
            if(B[u][i]){
                ch[u].push_back(i);
                dfs(i, u);
            }
        }
    }
}

int cop_pos= 0;
int start(int _N, bool A[MAX_N][MAX_N])
{
    N= _N;
    ch.resize(N);
    int ch_sz = 0;

    for(int i = 0; i<MAX_N; i++){
        for(int j = 0; j<MAX_N; j++){
            B[i][j] = A[i][j];
            if(B[i][j]){
                ch_sz++;
            }
        }
    }
    ch_sz/=2;
    if(ch_sz >N-1){
        return -1;
    }
    dfs(0, -1);

    
    return 0;
}

int find_ch(int u, int target){
    if(u == target){
        return target;
    }
    else{
        for(auto e: ch[u]){
            int i =find_ch(e, target);
            if(i!=-1){
                return e;
            }
        }
    }
    return -1;
}
int nextMove(int R)
{
    cop_pos = find_ch(cop_pos, R);
    return cop_pos;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...