# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1041567 |
2024-08-02T05:51:37 Z |
vjudge1 |
Izlet (COI19_izlet) |
C++17 |
|
924 ms |
46420 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 100;
int n, g, mat[N][N], par[N], col[N], cur_col;
set<int> reps;
vector<int> S[N];
vector<pair<int, int>> edges;
bool edge[N][N];
int root(int v){
return (par[v] == -1 ? v : par[v] = root(par[v]));
}
void merge(int u, int v){
if ((u = root(u)) == (v = root(v)))
return;
if (S[u].size() > S[v].size())
swap(u, v);
edges.push_back({u, v});
edge[u][v] = edge[v][u] = 1;
reps.erase(u);
par[u] = v;
for (int x : S[u]){
par[x] = v;
S[v].push_back(x);
}
S[u].clear();
}
int main(){
cin >> g >> n;
for (int i = 1; i <= n; i ++){
par[i] = -1, S[i] = {i};
reps.insert(i);
}
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
cin >> mat[i][j];
for (int i = 1; i <= n; i ++)
for (int j = i + 1; j <= n; j ++)
if (mat[i][j] == 1)
merge(i, j);
queue<int> q;
q.push(*reps.begin());
while (!q.empty()){
int v = q.front();
q.pop();
col[v] = ++cur_col;
for (int x : S[v])
col[x] = col[v];
for (int u : reps){
if (mat[u][v] == 2 and !edge[u][v]){
edge[u][v] = edge[v][u] = 1;
edges.push_back({u, v});
q.push(u);
}
}
}
for (int i = 1; i <= n; i ++)
cout << col[i] << " ";
cout << endl;
for (auto [u, v] : edges)
cout << u << " " << v << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Integer 64 violates the range [1, 30] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
924 ms |
46420 KB |
Integer 3001 violates the range [1, 3000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Integer 64 violates the range [1, 30] |
2 |
Halted |
0 ms |
0 KB |
- |