#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
const ll INF=63;
const int mxn=3e3+5;
bool DEBUG=0;
int a[mxn][mxn],n,subt;
int col[mxn];
bool vis[mxn];
vector<ii>edges;
vi adj[mxn];
void dfs(int u, int p=0){
vis[u]=1;
for(int v:adj[u]){
if(v==p)continue;
dfs(v,u);
}
}
void dfs2(int u, int p, int c){
col[u]=c;
for(int v:adj[u]){
if(v==p)continue;
dfs2(v,u,c);
}
}
//subtask 1
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
cin>>subt>>n;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
cin>>a[i][j];
if(i>j&&a[i][j]==1){
edges.eb(i,j);
adj[i].eb(j);
adj[j].eb(i);
}
}
}
if(subt!=1)return 0;
vi poor,cc;
for(int i=1; i<=n; i++){
if(sz(adj[i])==0)poor.eb(i);
else if(!vis[i]){
cc.eb(i);
dfs(i);
}
}
int c=0;
for(int i=0; i<sz(cc); i++){
dfs2(cc[i],0,c);
c=1-c;
if(i)edges.eb(cc[i],cc[i-1]);
}
if(sz(cc)){
for(int x:poor){
col[x]=!col[cc[0]];
edges.eb(x,cc[0]);
}
for(int i=1; i<=n; i++)cout<<col[i]+1<<" ";
cout<<"\n";
for(ii x:edges){
cout<<x.fi<<" "<<x.se<<"\n";
}
}else{
//all 2
for(int i=1; i<=n; i++)cout<<i%2+1<<" ";
cout<<"\n";
for(int i=1; i<n; i++){
cout<<i<<" "<<i+1<<"\n";
}
}
}
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
312 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
585 ms |
35700 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
312 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |