# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245484 | mhy908 | Izlet (COI19_izlet) | C++14 | 993 ms | 72288 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;
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]){
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){
if(arr[i][j]==arr[num][j]){
assert(tmp==0||col[j]==tmp||col[j]==col[num]);
tmp=col[j];
}
}
if(tmp)col[i]=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... |