#include "cmath"
#include "iostream"
#include "fstream"
#include "vector"
#include "ctime"
#include "iomanip"
using namespace std;
using std::vector;
#define N 10000//节点数
#define m 2.5 //平均度<k>=2m
double gamma=3;//gamma值在这改
void fast_search(int a,int b,double A[],double target,int& location){//from large to small
if(a==b){
if(target==A[a])
location=a;
}
if(a>b){
if(A[b]<=target){
location=b;
}
else{
location=0;
}
}
if(a==b-1){
if(A[a]<=target && A[b]>=target){
location=a;
}
if(A[b]<target){
location=b;
}
}
if(a<b-1){
int mid=(a+b)/2;
if(mid==a){
fast_search(mid+1,b,A,target,location);
}
if(mid>a){
if(A[mid]<target){
fast_search(mid,b,A,target,location);
}
if(A[mid]>target){
fast_search(a,mid,A,target,location);
}
if(A[mid]==target){
location=mid;
}
}
}
}
void gui_yi(double A[],int a,int b){
int i;double temp=0;
for(i=a;i<b;i++){
temp+=A[i];
}
for(i=a;i<b;i++){
A[i]=A[i]/temp;
}
}
int v_insert(vector<int>& v,int target){
int i=0;
if(v[0]==-1){
v.insert(v.begin(),target);
return 1;
}
if(v[0]!=-1){
if(v[0]>target){
v.insert(v.begin(),target);
return 1;
}
else if(v[0]==target)
return 0;
else{
while(v[i]!=-1 && v[i]<target)
i++;
if(v[i]==target)
return 0;
else{
v.insert(v.begin()+i,target);
return 1;
}
}
}
}
int lar_rand(){
int a,b,c;
a=rand()%1024;
b=rand()%1024;
c=1024*a+b;
return c;
}
int main(){
vector<int> A[N];
double p[N]={0},x[N]={0},p1,p2,r1,r2,n1024_2=1024*1024,sum;
int i,j,l1=0,l2=0,total_edges=0,return1,return2,i_deg[N]={0},deg[3000]={0};
ifstream fin;
ofstream fout;
for(i=1;i<N;i++){
A[i].push_back(-1);
}
for(i=1;i<N;i++)
p[i]=pow((double)i,-(double)(1/(gamma-1)));
gui_yi(p,1,N-1);
sum=0;
for(i=1;i<N;i++){
sum+=p[i];
p[i]=sum;
}
double p_m=p[1],f_i_j;
double p_m_2=pow((double)1200,2.0);
while(total_edges<m*(N-1)+1){
l1=0;l2=0;
r1=(double)lar_rand()/n1024_2;
r2=(double)lar_rand()/n1024_2;
fast_search(1,N-1,p,r1,l1);
fast_search(1,N-1,p,r2,l2);
if(l1!=0 && l2!=0 && l1!=l2){
return1=v_insert(A[l1],l2);
v_insert(A[l2],l1);
if(return1==1)
total_edges++;
}
}
fout.open("SF_net.txt");
int q;
int k;
int f;
int s=0;
double h=1;
fout<<N<<" "<<0<<endl;
for(i=1;i<N;i++)
{
q=0;
k=0;
f=0;
while(A[i][k]!=-1)
{
k++;
q++;
}
s=s+q;
fout<<i<<" "<<q;
while(A[i][f]!=-1)
{
fout<<" "<<A[i][f]<<" "<<setiosflags(ios::fixed)<<setprecision(6)<<h;
f++;
}
fout<<endl;
}
}