0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P2419 [USACO08JAN]Cow Contest S

R53034385
This commit is contained in:
Baoshuo Ren 2021-07-13 19:50:48 +08:00 committed by Baoshuo Ren
parent e90aeb21d7
commit 59d4fba0d7
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, f[105][105], ans[105];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = i == j ? 0 : 0x3f3f3f3f;
}
}
for (int i = 1; i <= m; i++) {
cin >> a >> b;
f[a][b] = 1;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (f[i][j] != 0x3f3f3f3f && f[i][j] > 0) {
ans[i]++;
ans[j]++;
}
}
}
for (int i = 1; i <= n; i++) {
if (ans[i] == n - 1) {
ans[0]++;
}
}
cout << ans[0] << endl;
return 0;
}