Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

迷之WA

Posted by liu_cheng_ao at 2016-09-14 12:52:22 on Problem 3256 and last updated at 2016-09-14 12:54:48
#include<cstdio>
#include<cstring>
#include<cstdlib>

using namespace std;
int k,n,m;
int nm[200],cnt[1200],ans=0,e[1200];
bool a[1010][1010];

void dfs(int q)
{
    e[q]=1;
    for(int i=1;i<=n;i++)
    if(a[q][i])
    {
               if(!e[i])dfs(i);
               for(int j=1;j<=n;j++)
               if(a[i][j])a[q][j]=true;
    }
}

int main()
{
    scanf("%d%d%d",&k,&n,&m);
    for(int i=1;i<=k;i++)
    scanf("%d",&nm[i]);
    for(int i=1;i<=m;i++)
    {int f,t;scanf("%d%d",&f,&t);a[f][t]=true;}
    for(int i=1;i<=n;i++)
    a[i][i]=true;
    for(int i=1;i<=k;i++)
    if(!e[nm[i]])
	dfs(nm[i]);
    for(int i=1;i<=k;i++)
    for(int j=1;j<=n;j++)
    if(a[nm[i]][j])cnt[j]++;
    for(int i=1;i<=n;i++)
    if(cnt[i]==k)ans++;
    printf("%d",ans);
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator