# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245489 | mhy908 | Izlet (COI19_izlet) | C++14 | 1171 ms | 97052 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>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int, int> pii;
int n;
int arr[3010][3010], col[3010], c, d[3010][3010];
vector<int> vc;
vector<pii> ed;
void dfs(int num){
vc.eb(num);
for(int i=1; i<=n; i++){
if(i==num)continue;
if(arr[num][i]==1&&!col[i]){
for(auto j:vc){
d[i][j]=d[num][j]+1;
d[j][i]=d[num][j]+1;
}
col[i]=col[num];
ed.eb(i, num);
}
}
for(int i=1; i<=n; i++){
if(arr[num][i]==2&&!col[i]){
int tmp=0;
for(auto j:vc){
d[i][j]=d[num][j]+1;
d[j][i]=d[num][j]+1;
}
for(auto j:vc){
if(arr[i][j]==arr[num][j]){
if(!tmp)tmp=j;
else if(d[i][tmp]>d[i][j])tmp=j;
}
}
if(tmp)col[i]=col[tmp];
else col[i]=++c;
ed.eb(i, num);
dfs(i);
}
}
}
int main(){
scanf("%*d %d", &n);
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
scanf("%d", &arr[i][j]);
}
}
col[1]=++c;
dfs(1);
for(int i=1; i<=n; i++)printf("%d ", col[i]);
puts("");
for(auto i:ed)printf("%d %d\n", i.F, i.S);
}
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... |