Submission #870732

# Submission time Handle Problem Language Result Execution time Memory
870732 2023-11-09T02:37:05 Z NeroZein Izlet (COI19_izlet) C++17
0 / 100
368 ms 72444 KB
#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 vis[N];  

vector<int> g[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]) continue;
    for (int j = 1; j <= n; ++j) {
      if (c[i][j] == 1 && i != j) {
        pr[j] = i;
        dep[j] = dep[i] + 1; 
        g[i].push_back(j); 
        g[j].push_back(i); 
      }
    }
  }
  pr[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; 
        g[v].push_back(i); 
        g[i].push_back(v); 
        que.push(i);
      }
    }
  }
  function<void(int, int, int, int)> Dfs = [&](int v, int p, int cur, int rt) {
    vis[v] = true; 
    for (int u : g[v]) {
      if (!col[u] || u == p) {
        continue; 
      }
      if (c[rt][u] == cur) {
        if (col[rt] && col[u] != col[rt]) {
          assert(false); 
        }
        col[rt] = col[u];
        return; 
      }
      Dfs(u, v, cur + 1, rt); 
    }
  };
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 1); 
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    return dep[i] < dep[j]; 
  });
  int cnt = 1; 
  for (int i : ord) {
    fill(vis, vis + n + 1, 0); 
    Dfs(i, i, 1, i); 
    if (!col[i]) {
      col[i] = cnt++; 
    }
  } 
  for (int i = 1; i <= n; ++i) {
    assert(col[i]); 
    cout << col[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 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 368 ms 72444 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -