답안 #870717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870717 2023-11-09T01:55:05 Z NeroZein Izlet (COI19_izlet) C++17
컴파일 오류
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int N = 3003;
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int N = 3003;

int pr[N]; 
int dep[N]; 
int col[N]; 
int c[N][N]; 

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> c[i][j]; 
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (pr[i] == 0) {
      for (int j = 2; j <= n; ++j) {
        if (c[i][j] == 1 && i != j) {
          pr[j] = i; 
        }
      }
    }
  }
  pr[1] = 1; 
  int cnt = 2; 
  col[1] = 1; 
  queue<int> que;
  que.push(1); 
  while (!que.empty()) {
    int v = que.front();
    que.pop(); 
    assert(dep[v] == c[1][v] - 1); 
    for (int i = 1; i <= n; ++i) {
      if (!pr[i] && c[v][i] == 2) {
        pr[i] = v; 
        que.push(i);
        dep[i] = dep[v] + 1; 
        int f = 0; 
        for (int j = 1; j <= n; ++j) {
          if (c[v][j] == c[i][j] && col[j] && (!f || dep[f] >= dep[j])) {
             f = j; 
          }
        }
        for (int j = 1; j <= n; ++j) {
          if (f && col[j] && c[v][j] == c[i][j] && dep[f] == dep[j]) {
            //assert(col[f] == col[j]); 
          }
        }
        if (!f) {
          col[i] = cnt++; 
        } else {
          assert(col[f]);
          col[i] = col[f]; 
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    assert(col[i] || col[pr[i]]); 
    cout << (col[i] ? col[i] : col[pr[i]]) << ' '; 
  }
  cout << '\n';
  for (int i = 2; i <= n; ++i) {
    assert(pr[i]); 
    cout << pr[i] << ' ' << i << '\n'; 
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> c[i][j]; 
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (pr[i] == 0) {
      for (int j = 2; j <= n; ++j) {
        if (c[i][j] == 1 && i != j) {
          pr[j] = i; 
        }
      }
    }
  }
  pr[1] = 1; 
  int cnt = 2; 
  col[1] = 1; 
  queue<int> que;
  que.push(1); 
  while (!que.empty()) {
    int v = que.front();
    que.pop(); 
    assert(dep[v] == c[1][v] - 1); 
    for (int i = 1; i <= n; ++i) {
      if (!pr[i] && c[v][i] == 2) {
        pr[i] = v; 
        que.push(i);
        dep[i] = dep[v] + 1; 
        int f = 0; 
        for (int j = 1; j <= n; ++j) {
          if (c[v][j] == c[i][j] && col[j] && (!f || dep[f] >= dep[j])) {
             f = j; 
          }
        }
        for (int j = 1; j <= n; ++j) {
          if (f && col[j] && c[v][j] == c[i][j] && dep[f] == dep[j]) {
            assert(col[f] == col[j]); 
          }
        }
        if (!f) {
          col[i] = cnt++; 
        } else {
          col[i] = col[f]; 
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    assert(col[i] || col[pr[i]]); 
    cout << (col[i] ? col[i] : col[pr[i]]) << ' '; 
  }
  cout << '\n';
  for (int i = 2; i <= n; ++i) {
    assert(pr[i]); 
    cout << pr[i] << ' ' << i << '\n'; 
  }
  return 0;
}

Compilation message

izlet.cpp:20:11: error: redefinition of 'const int N'
   20 | const int N = 3003;
      |           ^
izlet.cpp:10:11: note: 'const int N' previously defined here
   10 | const int N = 3003;
      |           ^
izlet.cpp:92:5: error: redefinition of 'int main()'
   92 | int main() {
      |     ^~~~
izlet.cpp:27:5: note: 'int main()' previously defined here
   27 | int main() {
      |     ^~~~