POJ-3660-Cow Contest [最短路][Floyd]
2017-08-22 08:45
357 查看
题目传送门
题意:给出许多牛之间的强弱关系,问可以确定多少牛的名次。
思路:用Floyd,如果一头牛与其他N-1头牛的关系确定,即这头牛的名次就固定。
题意:给出许多牛之间的强弱关系,问可以确定多少牛的名次。
思路:用Floyd,如果一头牛与其他N-1头牛的关系确定,即这头牛的名次就固定。
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> #include <queue> #include <map> #include <set> using namespace std; int mp[120][120]; int N,M; int main(void) { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(~scanf("%d %d", &N, &M)) { memset(mp,0,sizeof(mp)); while (M--) { int x, y; scanf("%d %d", &x, &y); mp[x][y]=1; } for (int k = 1; k <= N; k++) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { if (mp[i][k]==1 && mp[k][j]==1) { mp[i][j] = 1; } } } } int ans = 0; for (int i = 1; i <= N; i++) { int cnt = 0; for (int j = 1; j <= N; j++) { if (mp[i][j]==1 || mp[j][i]==1) cnt++; } ans = ans + (cnt==N-1?1:0); } printf("%d\n",ans); } return 0; }
相关文章推荐
- poj 3660 Cow Contest(最短路floyd)
- POJ3660 Cow Contest【最短路-floyd】
- POJ 3660 Cow Contest 最短路floyd
- POJ 3660 Cow Contest(Floyd最短路)
- Cow Contest(POJ 3660)(Floyd)(任意两点间最短路)
- POJ 3660 Cow Contest (全源最短路)
- POJ 3660 Cow Contest (最短路dijkstra)
- Floyd最短路——POJ 3360 Cow Contest
- POJ 3660 Cow Contest (Floyd 传递闭包)
- POJ-3660 Cow Contest( 最短路 )
- POJ - 3660 Cow Contest (floyd变形)
- POJ 3660 Cow Contest-floyd传递闭包
- POJ 3660 Cow Contest (floyd求联通关系)
- POJ 3660 Cow Contest (Floyd运用到传递闭包中~)
- POJ - 3660 Cow Contest(Floyd)
- POJ 3660 Cow Contest (Floyd)
- POJ 3660 Cow Contest(Floyd)
- POJ 3660 Cow Contest [Floyd]
- poj 3660 Cow Contest【floyd】
- Poj 3660 Cow Contest(Floyd解决传递闭包)