#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];
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] == 0) {
for (int j = 2; j <= n; ++j) {
if (c[i][j] == 1 && i != j) {
pr[j] = i;
g[i].push_back(j);
g[j].push_back(i);
}
}
}
}
queue<int> que;
que.push(1);
while (!que.empty()) {
int v = que.front();
que.pop();
for (int i = 2; 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);
}
}
}
int cnt = 0;
function<void(int, int, int, int)> Dfs = [&](int rt, int v, int p, int cur) {
for (int u : g[v]) {
if (!col[u] || u == p) {
continue;
}
if (cur == c[rt][u]) {
col[rt] = col[u];
return;
}
Dfs(rt, u, v, cur + 1);
}
};
vector<int> ord(n);
iota(ord.begin(), ord.end(), 1);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return dep[i] < dep[j];
});
for (int i : ord) {
Dfs(i, i, i, 1);
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
339 ms |
35812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |