#include <bits/stdc++.h>
using namespace std;
int n, tab[1000000]={}, x, per1=-1, per2=-1;
int main()
{
cin >> n;
for(int i=0;i<n;i++)
{
cin>>x;
tab[x]++;
}
for(int i=1;i<n;i++)
{
//cout << tab[i] <<"x"<<i<<endl;
if(tab[i]>i)
{
per1=i;
break;
}
else if(tab[i]==i)
{
if(per2==-1) per2=i;
}
}
if(per1>0)
{
cout << 0 << "\n" << per1+1 <<endl;
for(int j=0;j<per1+1;j++)
{
for(int jj=0;jj<per1+1;jj++)
{
if(j+1!=jj+1)cout << j+1 << " " << jj+1<<endl;
}
}
}
else if(per2>0)
{
cout << 1 << "\n" << per2+1 <<endl;
for(int j=0;j<per2+1;j++)
{
for(int jj=0;jj<per2+1;jj++)
{
if(j+1!=jj+1)cout << j+1 << " " << jj+1<<endl;
}
}
}
else
{
cout << "2\n2\n1 2\n2 1\n";
}
}
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 52 53 54 55 | #include <bits/stdc++.h> using namespace std; int n, tab[1000000]={}, x, per1=-1, per2=-1; int main() { cin >> n; for(int i=0;i<n;i++) { cin>>x; tab[x]++; } for(int i=1;i<n;i++) { //cout << tab[i] <<"x"<<i<<endl; if(tab[i]>i) { per1=i; break; } else if(tab[i]==i) { if(per2==-1) per2=i; } } if(per1>0) { cout << 0 << "\n" << per1+1 <<endl; for(int j=0;j<per1+1;j++) { for(int jj=0;jj<per1+1;jj++) { if(j+1!=jj+1)cout << j+1 << " " << jj+1<<endl; } } } else if(per2>0) { cout << 1 << "\n" << per2+1 <<endl; for(int j=0;j<per2+1;j++) { for(int jj=0;jj<per2+1;jj++) { if(j+1!=jj+1)cout << j+1 << " " << jj+1<<endl; } } } else { cout << "2\n2\n1 2\n2 1\n"; } } |
English