제출 #1053381

#제출 시각아이디문제언어결과실행 시간메모리
1053381kachim2경찰관과 강도 (BOI14_coprobber)C++17
0 / 100
1 ms344 KiB
#include "coprobber.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> graph;
int w, h;

bool cdfs(int v, int p){
    static vector<bool> vis(graph.size(), 0);
    if(vis[v]) return 1;
    vis[v] = 1;
    for(auto i : graph[v]){
        if(i!=p)
        if(cdfs( i, v)) return true;
    }
    return 0;
}
bool istree;
int start(int N, bool A[MAX_N][MAX_N])
{
    istree = !cdfs(0, -1);
    graph.resize(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(A[i][j]) graph[i].push_back(j);
        }
    }
    if(!istree){
    for(int i = 1; i < N; i++){
        if(graph[i].size() == 2) w=i+1;
    }
    h = N/w;
    }
    return 0;
}
int cpos = 0;
bool dfs(int r, int v, int p){
    if(v==r) return true;
    for(auto i : graph[v]){
        if(i!=p)
        if(dfs(r, i, v)) return true;
    }
    return false;
}
int nextMove(int R)
{
    int N = graph.size();
    if(!istree){
        int rx = R%w;
        int ry = R/w;
        int x = cpos%w;
        int y = cpos/w;
        if(abs(rx - x) > 1 ){
            if(x>rx)x--;
            else x++;
            return x+y*w;
        }else{
            if(y>ry)y--;
            else y++;
            return x+y*w;
        }



    }
    for(auto i : graph[cpos]){
        if(dfs(R, i, cpos)){
            cpos = i;
            return i;
        }
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

coprobber.cpp: In function 'int nextMove(int)':
coprobber.cpp:46:9: warning: unused variable 'N' [-Wunused-variable]
   46 |     int N = graph.size();
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...