Submission #1041476

# Submission time Handle Problem Language Result Execution time Memory
1041476 2024-08-02T04:35:39 Z vjudge1 Izlet (COI19_izlet) C++17
0 / 100
253 ms 35888 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)
{
	if (b>c)
		swap(b,c);
	return (a[b][c-1]==a[b][c]);
}
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();
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 253 ms 35888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -