zoukankan      html  css  js  c++  java
  • 2019-2020 ACM-ICPC Latin American Regional Programming Contest I

    #include<iostream>
    #include<cstring>
    #define int long long
    using namespace std;
    const int N=4010,mod=1e9+7;
    int a[N];
    int e[N*N],ne[N*N],idx,h[N];
    int st[N];
    int ans;
    int ans1[N];
    int read()
    {
    	int res=0,ch,flag=0;
    	if((ch=getchar())=='-')             //判断正负
    		flag=1;
    	else if(ch>='0'&&ch<='9')           //得到完整的数
    		res=ch-'0';
    	while((ch=getchar())>='0'&&ch<='9')
    		res=res*10+ch-'0';
    	return flag?-res:res;
    }
    void add(int a,int b)
    {
    	e[idx]=b;
    	ne[idx]=h[a];
    	h[a]=idx++;
    }
    int dp[N];
    int res;
    int dfs(int u,int fa)
    {
    	if(dp[u]!=-1)
    		return dp[u];
    	if(st[u]==0)
    	{
    		res++;
    		dp[u]=1;
    		return dp[u];
    	}
    	int sum=0;
    	for(int i=h[u]; i!=-1; i=ne[i])
    	{
    		int j=e[i];
    		if(j==fa)
    			continue;
    		sum=(sum+(dfs(j,u)%mod))%mod;
    	}
    	dp[u]=sum;
    	return sum;
    }
    signed main()
    {
    	memset(dp,-1,sizeof dp);
    	memset(h,-1,sizeof h);
    	int n=read(),l=read();
    	for(int i=1; i<=l; i++)
    	{
    		st[i]=1;
    		int k=read();
    		while(k--)
    		{
    			int a=i;
    			int b=read();
    			add(i,b);
    		}
    	}
    	ans=dfs(1,-1);
    	cout<<ans%mod<<" "<<res%mod<<endl;
    }
    
  • 相关阅读:
    codeforces 980A Links and Pearls
    zoj 3640 Help Me Escape
    sgu 495 Kids and Prizes
    poj 3071 Football
    hdu 3853 LOOPS
    hdu 4035 Maze
    hdu 4405 Aeroplane chess
    poj 2096 Collecting Bugs
    scu 4444 Travel
    zoj 3870 Team Formation
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12665010.html
Copyright © 2011-2022 走看看