답안 #485093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485093 2021-11-06T07:26:48 Z Trunkty Izlet (COI19_izlet) C++14
18 / 100
881 ms 369420 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;
vector<vector<int>> ord[3005];
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;
	bool all=true;
	for(int i:checked){
		if(arr[x][i]==arr[par][i]){
			iscol = col[i];
		}
		else{
			all = false;
		}
	}
	if(all){
		col[x] = col[par];
	}
	else{
		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);
    col[0] = 1;
    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[arr[i][j]].push_back({i,j});
			}
		}
	}
	for(int j=1;j<=n;j++){
		for(vector<int> i:ord[j]){
			domerge(i[0],i[1]);
		}
	}
	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 868 ms 354872 KB Output is correct
3 Correct 870 ms 355008 KB Output is correct
4 Correct 881 ms 363840 KB Output is correct
5 Correct 846 ms 369420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 833 ms 356492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 868 ms 354872 KB Output is correct
3 Correct 870 ms 355008 KB Output is correct
4 Correct 881 ms 363840 KB Output is correct
5 Correct 846 ms 369420 KB Output is correct
6 Incorrect 833 ms 356492 KB Output isn't correct
7 Halted 0 ms 0 KB -