为什么纯数组模拟全WA vector模拟就ac了 数组模拟测试样例也没问题啊
查看原帖
为什么纯数组模拟全WA vector模拟就ac了 数组模拟测试样例也没问题啊
1604797
zsc2094435373楼主2025/2/6 20:12
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
const int N=1e3+10,M=1e5+10;

PII A[M];
int h[N],e[M],ne[M],idx;
int n,m,d[N];
int cnt[1001000];

int edge[N][N];
bool cmp(PII p1,PII p2)
{
	if(p1.first==p2.first) return p1.second>p2.second;
	else return p1.first>p2.first;
}

void add(int a,int b)
{
	e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}

int main()
{
	cin>>n>>m;
	memset(h,-1,sizeof(h));
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		A[i]={a,b};
		edge[a][b]=1,edge[b][a]=1;
	}
	sort(A,A+m,cmp);
	for(int i=0;i<m;i++)
	{
		if(cnt[A[i].first*1000+A[i].second]==0)
		{
			cnt[A[i].first*1000+A[i].second]++;
			add(A[i].first,A[i].second);
			add(A[i].second,A[i].first);
			d[A[i].first]++;
			d[A[i].second]++;
		}
	}	
	
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			 cout<<edge[i][j];
			 if(j<n)cout<<" "; 
		}
		cout<<endl;
	}
	
	for(int i=1;i<=n;i++)//遍历每条链表 
	{
		cout<<d[i]<<" " ;
		for(int j=h[i];j!=-1;j=ne[j])
		{
			cout<<e[j]<<" ";
		}
		cout<<endl; 
	}


    return 0;
}

2025/2/6 20:12
加载中...