# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
331769 | thecodingwizard | Izlet (COI19_izlet) | C++11 | 591 ms | 53740 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010
#define maxn 3000
int n;
int input[maxn][maxn];
vector<int> nodes; // stores nodes remaining after 1's are compressed
map<int, vector<int>> nodesInOneComponent;
void compressOnes() {
vector<bool> done(n, 0);
F0R(i, n) {
if (done[i]) continue;
nodes.pb(i);
done[i] = true;
F0R(j, n) {
if (input[i][j] == 1 && j != i) {
nodesInOneComponent[i].pb(j);
done[j] = true;
}
}
}
}
void findTwos() {
}
int assignedColor[maxn];
vector<ii> outputEdges;
void buildTree() {
assignedColor[nodes[0]] = 1;
FOR(i, 1, nodes.size()) {
outputEdges.emplace_back(nodes[0], nodes[i]);
assignedColor[nodes[i]] = 2;
}
}
void decompressOnes() {
for (int x : nodes) {
for (int y : nodesInOneComponent[x]) {
outputEdges.pb(mp(x, y));
assignedColor[y] = assignedColor[x];
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int subtask; cin >> subtask; assert(subtask == 1);
cin >> n;
F0R(i, n) {
F0R(j, n) {
cin >> input[i][j];
}
}
compressOnes();
findTwos();
buildTree();
decompressOnes();
F0R(i, n) cout << assignedColor[i] << " ";
cout << endl;
for (auto x : outputEdges) cout << x.f+1 << " " << x.s+1 << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |