# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245489 | 2020-07-06T14:14:09 Z | mhy908 | Izlet (COI19_izlet) | C++14 | 1171 ms | 97052 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 1051 ms | 71276 KB | Output is correct |
3 | Correct | 1036 ms | 71596 KB | Output is correct |
4 | Correct | 971 ms | 58616 KB | Output is correct |
5 | Correct | 1000 ms | 64892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1079 ms | 69848 KB | Output is correct |
2 | Correct | 1018 ms | 67712 KB | Output is correct |
3 | Correct | 1163 ms | 71544 KB | Output is correct |
4 | Correct | 1171 ms | 71932 KB | Output is correct |
5 | Correct | 940 ms | 64700 KB | Output is correct |
6 | Correct | 1002 ms | 67876 KB | Output is correct |
7 | Correct | 734 ms | 56568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 1051 ms | 71276 KB | Output is correct |
3 | Correct | 1036 ms | 71596 KB | Output is correct |
4 | Correct | 971 ms | 58616 KB | Output is correct |
5 | Correct | 1000 ms | 64892 KB | Output is correct |
6 | Correct | 1079 ms | 69848 KB | Output is correct |
7 | Correct | 1018 ms | 67712 KB | Output is correct |
8 | Correct | 1163 ms | 71544 KB | Output is correct |
9 | Correct | 1171 ms | 71932 KB | Output is correct |
10 | Correct | 940 ms | 64700 KB | Output is correct |
11 | Correct | 1002 ms | 67876 KB | Output is correct |
12 | Correct | 734 ms | 56568 KB | Output is correct |
13 | Correct | 1135 ms | 71160 KB | Output is correct |
14 | Correct | 1144 ms | 97052 KB | Output is correct |
15 | Correct | 983 ms | 87640 KB | Output is correct |
16 | Correct | 1046 ms | 92280 KB | Output is correct |
17 | Correct | 1049 ms | 88756 KB | Output is correct |
18 | Correct | 1074 ms | 88836 KB | Output is correct |
19 | Correct | 1000 ms | 82680 KB | Output is correct |
20 | Correct | 992 ms | 87364 KB | Output is correct |
21 | Correct | 1025 ms | 84736 KB | Output is correct |
22 | Correct | 1070 ms | 88736 KB | Output is correct |
23 | Correct | 1041 ms | 89080 KB | Output is correct |
24 | Correct | 1074 ms | 95832 KB | Output is correct |
25 | Correct | 1004 ms | 88440 KB | Output is correct |