Submission #870713

# Submission time Handle Problem Language Result Execution time Memory
870713 2023-11-09T01:39:32 Z NeroZein Izlet (COI19_izlet) C++17
18 / 100
355 ms 35960 KB
#include "bits/stdc++.h"
using namespace std;

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

const int N = 3003;

int p[N]; 
int pr[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]; 
    }
  }
  vector<pair<int, int>> ans; 
  for (int i = 1; i <= n; ++i) {
    if (p[i] == 0) {
      for (int j = 1; j <= n; ++j) {
        if (c[i][j] == 1) {
          p[j] = i; 
          if (i != j) {
            pr[j] = i; 
            ans.emplace_back(i, j); 
          }
        }
      }
    }
  }
  pr[1] = 1; 
  int cnt = 2; 
  col[1] = 1; 
  queue<int> que;
  que.push(1); 
  while (!que.empty()) {
    int v = que.front();
    que.pop(); 
    for (int i = 1; i <= n; ++i) {
      if (!pr[i] && c[v][i] == 2) {
        pr[i] = v; 
        que.push(i);
        bool f = false; 
        for (int j = 1; j <= n; ++j) {
          if (c[v][j] == c[i][j] && col[j]) {
            f = true;
            col[i] = col[j]; 
            break; 
          }
        }
        if (!f) {
          col[i] = cnt++; 
        }
      }
    }
  }
  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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 329 ms 35716 KB Output is correct
3 Correct 355 ms 35960 KB Output is correct
4 Correct 328 ms 35736 KB Output is correct
5 Correct 332 ms 35496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 331 ms 35668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 329 ms 35716 KB Output is correct
3 Correct 355 ms 35960 KB Output is correct
4 Correct 328 ms 35736 KB Output is correct
5 Correct 332 ms 35496 KB Output is correct
6 Incorrect 331 ms 35668 KB Output isn't correct
7 Halted 0 ms 0 KB -