# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
705057 |
2023-03-03T10:05:35 Z |
Nursik |
Izlet (COI19_izlet) |
C++14 |
|
444 ms |
53520 KB |
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <random>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 3e3 + 10, maxm = 20 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, blcok = 400, p2 = 31;
const ld eps = 1e-9;
int s, n, a[maxn][maxn], p[maxn], sz[maxn], color[maxn];
vector<int> comps[maxn];
int get(int v){
if (v == p[v])
return v;
return p[v] = get(p[v]);
}
void unite(int a, int b){
a = get(a), b = get(b);
if (a == b)
return;
if (sz[a] > sz[b])
swap(a, b);
p[a] = b;
sz[b] += sz[a];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> s;
cin >> n;
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= n; ++j){
cin >> a[i][j];
}
}
for (int i = 1; i <= n; ++i){
p[i] = i, sz[i] = 1;
}
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= n; ++j){
if (a[i][j] == 1){
unite(i, j);
}
}
}
int root = get(1);
for (int i = 1; i <= n; ++i){
if (get(i) == root){
color[i] = 1;
}
else{
color[i] = 2;
}
comps[get(i)].pb(i);
cout << color[i] << " ";
}
cout << '\n';
vector<pair<int, int>> ans;
for (int i = 1; i <= n; ++i){
int sz = (int)comps[i].size() - 1;
for (int j = 0; j < sz; ++j){
ans.pb(mp(comps[i][j], comps[i][j + 1]));
}
if ((int)comps[i].size() > 0 && i != root){
ans.pb(mp(comps[i][0], root));
}
}
for (auto it : ans){
cout << it.f << " " << it.s << '\n';
}
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
400 ms |
35860 KB |
Output is correct |
3 |
Correct |
444 ms |
53508 KB |
Output is correct |
4 |
Correct |
410 ms |
53520 KB |
Output is correct |
5 |
Correct |
388 ms |
53288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
414 ms |
35832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
400 ms |
35860 KB |
Output is correct |
3 |
Correct |
444 ms |
53508 KB |
Output is correct |
4 |
Correct |
410 ms |
53520 KB |
Output is correct |
5 |
Correct |
388 ms |
53288 KB |
Output is correct |
6 |
Incorrect |
414 ms |
35832 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |