Think:
1知识点:最短路+_Floyd()算法求传递背包数量
2反思:学习知识要努力拓展创新
以下为Accepted代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e2 + 4;
int n, e[N][N];
void Floyd();
int main(){
int m, i, j, u, v, sum, ans;
while(~scanf("%d %d", &n, &m)){
ans = 0;
memset(e, 0, sizeof(e));
for(i = 1; i <= m; i++){
scanf("%d %d", &u, &v);
e[u][v] = 1;
}
Floyd();
for(i = 1; i <= n; i++){
sum = 0;
for(j = 1; j <= n; j++){
if(e[i][j] || e[j][i])
sum++;
}
if(sum == n-1)
ans++;
}
printf("%d\n", ans);
}
return 0;
}
void Floyd(){
int i, j, k;
for(k = 1; k <= n; k++){
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
if(e[i][k] && e[k][j])
e[i][j] = 1;
}
}
}
}