为什么输出0,求调壶关
查看原帖
为什么输出0,求调壶关
1632297
ymgh楼主2025/7/23 16:25
#include<bits/stdc++.h>
using namespace std;
const int mod=80112002;
int indegree[5001],chdegree[5001];
int head[5001];
struct node{
	int nxt,to;
}edge[500005];
int cnt;
int dp[5005];
void add(int from,int to){
	cnt++;
	edge[cnt].to=to;
	edge[cnt].nxt=head[from];
	head[from]=cnt;
}
int n,m;
queue < int > q;
void tupo(){
	for(int i=1;i<=n;i++){
		if(indegree[i]==0){
			dp[i]=1;
			q.push(i);
		}
	}
	while(!q.empty()){
		for(int i=head[q.front()];i;i=edge[i].nxt){
			int y=edge[i].to;
			dp[y]=(dp[y]+dp[i])%mod;
			indegree[y]--;
			if(indegree[y]==0){
				q.push(y);
			}
		}
		q.pop();
	}
}
int main(){
	cin>>n>>m;
	int a,b;
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=m;i++){
		cin>>a>>b;
		add(a,b); 
		indegree[b]++;
		chdegree[a]++;
	}
	tupo();
	int ans=0;
	for(int i=1;i<=n;i++){
		if(chdegree[i]==0){
			ans=(ans+dp[i])%mod;
		}
	}
	cout<<ans<<endl;
	return 0;
} 
2025/7/23 16:25
加载中...