Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 3086 | Accepted: 1438 |
Description
Each of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ would like to order his cows according to these rates from the fastest milk producer to the slowest.
FJ has already compared the milk output rate for M (1 ≤ M ≤ 10,000) pairs of cows. He wants to make a list ofC additional pairs of cows such that, if he now compares those C pairs, he will definitely be able to deduce the correct ordering of allN cows. Please help him determine the minimum value of C for which such a list is possible.
Input
Output
Sample Input
5 5 2 1 1 5 2 3 1 4 3 4
Sample Output
3
Hint
代码:
/*************************************************************************
> Author: wzw-cnyali
> Created Time: 2017/8/29 15:48:29
************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#prag\
ma GCC optimize("O3")
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
#define REP(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define DREP(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define EREP(i, a) for(register int i = (be[a]); i != -1; i = nxt[i])
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mem(a, b) memset((a), b, sizeof(a))
template inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
char buff[1 << 25], *buf = buff;
template
T read(T sum = 0, T fg = 0)
{
while(*buf < '0' || *buf > '9') { fg |= *buf == '-'; buf++; }
while(*buf >= '0' && *buf <= '9') { sum = sum * 10 + *buf - '0'; buf++; }
return fg ? -sum : sum;
}
const int Size = 1010;
bitset MAP[Size];
void floyd(int n)
{
REP(i, 1, n) REP(j, 1, n)
if(MAP[j][i]) MAP[j] |= MAP[i];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
fread(buff, 1, 1 << 25, stdin);
int n = read(), m = read();
REP(i, 1, m)
{
int x = read(), y = read();
MAP[x][y] = 1;
}
floyd(n);
int ans = 0;
REP(i, 1, n) REP(j, i + 1, n)
if(!MAP[i][j] && !MAP[j][i]) ans++;
printf("%d\n", ans);
return 0;
}