답안 #1041473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041473 2024-08-02T04:33:55 Z vjudge1 Izlet (COI19_izlet) C++17
0 / 100
2000 ms 63416 KB
/*
بسم الله الرحمن الرحيم
Author:
                          (:Muhammad Aneeq:)
*/

#include <iostream>
#include <vector>
using namespace std;
int const N=3e3+10;
int par[N]={};
vector<int>mem[N]={};
int a[N][N]={};
int root(int n)
{
	if (par[n]==n) return n;
	return (par[n]=root(par[n]));
}
bool merge_able(int c,int b)
{
	for (auto i:mem[c])
	{
		for (auto j:mem[b])
		{
			int u=i,v=j;
			if (u>v)
				swap(u,v);
			if (a[u][v-1]!=a[u][v])
				return 0;
		}
	}
	return 1;
}
void merge(int a,int b)
{
	a=root(a);b=root(b);
	if (a==b)
		return;
	if (merge_able(a,b)==0)
		return ;
	for (auto i:mem[b])
		mem[a].push_back(i);
	mem[b]={};
	par[b]=a;
}
inline void solve()
{
	int subt;
	cin>>subt;
	int n;
	cin>>n;
	for (int i=0;i<n;i++)
		par[i]=i,mem[i].push_back(i);
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			cin>>a[i][j];
	if (subt==2)
	{
		for (int i=1;i<n;i++)
		{
			for (int j=0;j<n-i;j++)
			{
				merge(j,i+j);
			}
		}
		for (int i=0;i<n;i++)
			cout<<root(i)+1<<' ';
		cout<<endl;
		for (int i=1;i<n;i++)
			cout<<i<<' '<<i+1<<endl;
	}
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 628 ms 44912 KB Output is correct
2 Correct 872 ms 48208 KB Output is correct
3 Correct 410 ms 62028 KB Output is correct
4 Correct 345 ms 63416 KB Output is correct
5 Execution timed out 2071 ms 48944 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -