D. Districts Connection(思维+构造)

98 篇文章 3 订阅

https://codeforces.com/contest/1433/problem/D


思路:构造的形状类似树,所以直接把1个帮派通过树连接成一个和它不同编号的多叉树。然后找到第二层的任意一个结点,再把根节点对应的帮派连成一个多叉树。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=5e3+100;
typedef long long LL;
LL a[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--)
  {
  	LL n;cin>>n;
  	for(LL i=1;i<=n;i++) cin>>a[i];
  	LL idx=-1;
  	vector<pair<LL,LL>>pr;
  	for(LL i=2;i<=n;i++)
  	{
  		if(a[i]!=a[1]){
  			pr.push_back({1,i});
			idx=i;	
		}
	}
	if(idx==-1) {
		cout<<"NO"<<endl;
		continue;
	}
	else{
		for(LL i=2;i<=n;i++)
		{
			if(a[i]==a[1]){
				pr.push_back({idx,i});
			}
		}
		cout<<"YES"<<endl;
		for(auto i:pr){
			cout<<(i.first)<<" "<<(i.second)<<endl;
		}
	}
  }
return 0;
}
 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值