# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
485089 |
2021-11-06T07:15:30 Z |
Trunkty |
Izlet (COI19_izlet) |
C++14 |
|
2000 ms |
368416 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
int n;
vector<vector<int>> ans,ord;
int arr[3005][3005];
int par[3005];
vector<int> roads[3005];
int col[3005];
vector<int> checked;
int findpar(int x){
if(x!=par[x]){
int p = findpar(par[x]);
par[x] = p;
}
return par[x];
}
void domerge(int a, int b){
if(findpar(a)!=findpar(b)){
ans.push_back({a,b});
par[findpar(a)] = findpar(b);
roads[a].push_back(b);
roads[b].push_back(a);
}
}
void dfs(int x, int par){
int iscol = x;
for(int i:checked){
if(arr[x][i]==arr[par][i]){
iscol = col[i];
}
}
col[x] = iscol;
checked.push_back(x);
for(int i:roads[x]){
if(i!=par){
dfs(i,x);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int sub;
cin >> sub;
cin >> n;
for(int i=1;i<=n;i++){
par[i] = i;
for(int j=1;j<=n;j++){
cin >> arr[i][j];
if(i<j){
ord.push_back({arr[i][j],i,j});
}
}
}
sort(ord.begin(),ord.end());
for(vector<int> i:ord){
domerge(i[1],i[2]);
}
dfs(1,0);
for(int i=1;i<=n;i++){
cout << col[i] << " ";
}
cout << "\n";
for(vector<int> i:ans){
cout << i[0] << " " << i[1] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1281 ms |
368064 KB |
Output is correct |
3 |
Correct |
1289 ms |
368076 KB |
Output is correct |
4 |
Correct |
1641 ms |
368232 KB |
Output is correct |
5 |
Correct |
1692 ms |
368416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2101 ms |
367948 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1281 ms |
368064 KB |
Output is correct |
3 |
Correct |
1289 ms |
368076 KB |
Output is correct |
4 |
Correct |
1641 ms |
368232 KB |
Output is correct |
5 |
Correct |
1692 ms |
368416 KB |
Output is correct |
6 |
Execution timed out |
2101 ms |
367948 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |