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:
parent
e90aeb21d7
commit
59d4fba0d7
40
Luogu/problem/P2419/P2419.cpp
Normal file
40
Luogu/problem/P2419/P2419.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user