记录一个菜逼的成长。。
将顶点按能到达的点数从小到大排序,排好序之后每个点只能往前面的点连边. 因而如果存在一个排在第i位的点,要求到达的点数大于i-1,则不可行;否则就可以按照上述方法构造出图. 复杂度O(N^2).
PS:一道水题,训练的时候条件漏了。。好TM菜啊。Orz.
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <deque>
#include <cctype>
#include <bitset>
#include <cmath>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define cl(a) memset(a,0,sizeof(a))
#define fin freopen("D://in.txt","r",stdin)
#define fout freopen("D://out.txt","w",stdout)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1000 + 10;
VPII a,b;
bool cmp(PII a,PII b)
{
if(a.first != b.first)return a.first < b.first;
return a.second < b.second;
}
int main()
{
//fin;
//fout;
int T,cas = 1;
scanf("%d",&T);
while(T--){
a.clear();
b.clear();
int n;
scanf("%d",&n);
bool flag = true;
for( int i = 1,x; i <= n; i++ ){
scanf("%d",&x);
a.push_back(PII(x,i));
}
sort(ALL(a),cmp);
for( int i = 0; i < n; i++ ){
if(a[i].first > i){
flag = false;
break;
}
if(!a[i].first){
for( int j = i + 1; j < n; j++ ){
if(a[j].first){
a[j].first--;
b.push_back(PII(a[j].second,a[i].second));
}
}
}
}
printf("Case #%d: %s\n",cas++,flag?"Yes":"No");
if(flag){
printf("%d\n",b.size());
for( int i = 0; i < b.size(); i++ ){
printf("%d %d\n",b[i].first,b[i].second);
}
}
}
return 0;
}