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

就判断一下每个点前面的点的个数和后面的点的个数就可以了

Posted by 10041112acmer at 2013-08-20 10:56:07 on Problem 3660
RT:

http://blog.csdn.net/acm_zl?viewmode=contents

int main()
{
    scanf("%d%d", &n, &m);
    memset(g, 0, sizeof(g));
    for (int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a][b] = true;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                if (g[j][i] && g[i][k])
                    g[j][k] = true;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int temp = 0;
        for (int j = 1; j <= n; j++)
            temp += g[i][j] + g[j][i];//如果g[i][j],则表示有出边,如果g[j][i],则表示有入边
        //cout << temp << endl;
        if (temp == n - 1)
            ans++;
    }
    printf("%d\n", 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