제출 #252505

#제출 시각아이디문제언어결과실행 시간메모리
252505eohomegrownapps게임 (IOI14_game)C++14
컴파일 에러
0 ms0 KiB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> adjmat;
vector<vector<int>> numnotconn;
vector<int> ufds;
vector<int> usize;
int n;
int root(int i){
    if (ufds[i]==i){
        return i;
    } else {
        return ufds[i]=root(ufds[i]);
    }
}

void connect(int a, int b){
    int ra = root(a);
    int rb = root(b);
    if (ra==rb){return;}
    //path compression
    ufds[ra]=rb;
    usize[rb]+=usize[ra];
    //new root: rb
    for (int i = 0; i<n; i++){
        numnotconn[rb][i]+=numnotconn[ra][i];
        numnotconn[i][rb]+=numnotconn[i][ra];
    }
}

//0 - no, 1 - yes, 2 - unchecked
void initialize(int N) {
    n=N;
    adjmat.resize(n,vector<int>(n,2));
    numnotconn.resize(n,vector<int>(n,0));
    ufds.resize(n);
    usize.resize(n,1);
    for (int i = 0; i<n; i++){
        ufds[i]=i;
    }
}

void ret0(int u, int v){
    adjmat[u][v]=0;
    adjmat[v][u]=0;
    numnotconn[ru][rv]++;
    numnotconn[rv][ru]++;
}

void ret1(int u, int v){
    adjmat[u][v]=1;
    adjmat[v][u]=1;
    connect(u,v);
}

int hasEdge(int u, int v) {
    int ru = root(u);
    int rv = root(v);
    if (ru==rv){
        ret1();
        return 1;
    }
    //check neighbours of u
    //cout<<u<<" "<<v<<'\n';
    for (int i = 0; i<n; i++){
        if (i==u||i==v){continue;}
        if (adjmat[u][i]==1){
            //cout<<"neighbour "<<i<<'\n';
            if (adjmat[i][v]==2){
                //must put 0
                ret0();
                return 0;
            }
        }
        if (adjmat[v][i]==1){
            //cout<<"neighbour "<<i<<'\n';
            if (adjmat[i][u]==2){
                //must put 0
                ret0();
                return 0;
            }
        }
    }
    if (usize[ru]+usize[rv]==n){
        ret0();
        return 0;
    }
    if (numnotconn[ru][rv]==(usize[ru]*usize[rv]-1)){
        ret1();
        return 1;
    }
    ret0();
    return 0;
}

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

game.cpp: In function 'void ret0(int, int)':
game.cpp:47:16: error: 'ru' was not declared in this scope
     numnotconn[ru][rv]++;
                ^~
game.cpp:47:16: note: suggested alternative: 'u'
     numnotconn[ru][rv]++;
                ^~
                u
game.cpp:47:20: error: 'rv' was not declared in this scope
     numnotconn[ru][rv]++;
                    ^~
game.cpp:47:20: note: suggested alternative: 'v'
     numnotconn[ru][rv]++;
                    ^~
                    v
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:61:14: error: too few arguments to function 'void ret1(int, int)'
         ret1();
              ^
game.cpp:51:6: note: declared here
 void ret1(int u, int v){
      ^~~~
game.cpp:72:22: error: too few arguments to function 'void ret0(int, int)'
                 ret0();
                      ^
game.cpp:44:6: note: declared here
 void ret0(int u, int v){
      ^~~~
game.cpp:80:22: error: too few arguments to function 'void ret0(int, int)'
                 ret0();
                      ^
game.cpp:44:6: note: declared here
 void ret0(int u, int v){
      ^~~~
game.cpp:86:14: error: too few arguments to function 'void ret0(int, int)'
         ret0();
              ^
game.cpp:44:6: note: declared here
 void ret0(int u, int v){
      ^~~~
game.cpp:90:14: error: too few arguments to function 'void ret1(int, int)'
         ret1();
              ^
game.cpp:51:6: note: declared here
 void ret1(int u, int v){
      ^~~~
game.cpp:93:10: error: too few arguments to function 'void ret0(int, int)'
     ret0();
          ^
game.cpp:44:6: note: declared here
 void ret0(int u, int v){
      ^~~~