# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
870730 |
2023-11-09T02:28:25 Z |
NeroZein |
Izlet (COI19_izlet) |
C++17 |
|
363 ms |
72532 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)> Dfs = [&](int v, int p, int cur) {
vis[v] = true;
for (int u : g[v]) {
if (!col[u] || u == p) {
continue;
}
if (c[v][u] == cur) {
if (col[v]) assert(col[v] == col[u]);
col[v] = col[u];
return;
}
Dfs(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];
});
int cnt = 1;
for (int i : ord) {
fill(vis, vis + n + 1, 0);
Dfs(i, i, 1);
if (!col[i]) {
col[i] = cnt++;
}
}
for (int i = 1; i <= n; ++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 |
Runtime error |
3 ms |
4956 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
363 ms |
72532 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
4956 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |