답안 #709790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709790 2023-03-14T12:25:46 Z ngano_upat_na 게임 (APIO22_game) C++17
컴파일 오류
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int N = 300000;
int K = -1;
bool done = false;
bool cyc = false;
vector<int> adj[N];
vector<bool> vis(N,false);

void dfs(int u) {
    if (vis[u]) {
        cyc = true;
        return;
    }
    vis[u] = true;
    for (auto &v:adj[u]) {
        dfs(v);
    }   
}   


void init(int n, int k) {
    N = n;
    K = k;
    for (int i=0; i<=k-2; i++) {
        adj[i].push_back(i+1);
    }   
}   

int add_teleporter(int u, int v) {
    adj[u].push_back(v);
    
    if (done) return 1;
    for (int i=0; i<N; i++) {
        vis[i] = false;
    }   
    cyc = false;
    dfs(0);
    
    if (cyc) return 1;
    return 0;
}   

Compilation message

game.cpp:9:18: error: array bound is not an integer constant before ']' token
    9 | vector<int> adj[N];
      |                  ^
game.cpp: In function 'void dfs(int)':
game.cpp:18:18: error: 'adj' was not declared in this scope
   18 |     for (auto &v:adj[u]) {
      |                  ^~~
game.cpp: In function 'void init(int, int)':
game.cpp:28:9: error: 'adj' was not declared in this scope
   28 |         adj[i].push_back(i+1);
      |         ^~~
game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:33:5: error: 'adj' was not declared in this scope
   33 |     adj[u].push_back(v);
      |     ^~~