找朋友 的内存超限代码

可供参考!

 1 #include<iostream>
 2 using namespace std;
 3 long long a[10000][20000],b[10000];
 4 int main()
 5 {
 6     int n,m,x,y;
 7     cin>>n>>m;
 8     for(int i=0;i<m;i++)
 9     {
10         cin>>x>>y;
11         b[x]++;
12         b[y]++;
13         a[x][b[x]-1]=y;
14         a[y][b[y]-1]=x;
15     }
16     for(int i=0;i<n;i++)
17     {
18         cout<<"Friends of "<<i+1<<" : ";
19         bool flag=1;
20         for(int j=b[i+1]-1;j>=0;j--)
21         {
22             if(flag==1)
23             {
24                 cout<<a[i+1][j];
25                 flag=0;
26             }
27             else
28                 cout<<" "<<a[i+1][j];
29         }
30         cout<<endl;
31     }
32     system("pause");
33     return 0;
34 }
原文地址:https://www.cnblogs.com/Semora-2004/p/5702584.html