Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
就判断一下每个点前面的点的个数和后面的点的个数就可以了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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator