Codeforces Round #677 (Div. 3) D/1433D Districts Connection

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

找两个不同权值的节点A、B连起来,所有与A不同权值的连到A上,相同的连到B上。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#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;
}
  

  


 

posted on   mrwu  阅读(80)  评论(0编辑  收藏  举报

努力加载评论中...
点击右上角即可分享
微信分享提示