https://codeforces.com/contest/1433/problem/D
找两个不同权值的节点A、B连起来,所有与A不同权值的连到A上,相同的连到B上。
#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; }