同学可以开到 5e3 + 5 AC , 我开到 101 MLE ;
求助
源代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
//#define int long long
#define INF 0x3f3f3f
#define inf -0x3f3f3f
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std ;
int n , m ;
bool f[101][101] ;
int ans ;
inline void read(int &x) {
bool ok ; char ch ;
for(ok = false , ch = getchar() ; !isdigit(ch) ; ch = getchar()) {
if(ch == '-') ok = true ;
}
for(x = 0 ; isdigit(ch) ; x = x * 10 + ch - '0' , ch = getchar()) {
if(ok) x = -x ;
}
}
inline void write(int x) {
if(n < 0) {
putchar('-') ;
x *= -x ;
}
if(n > 9) write(x / 10) ;
putchar(x % 10 + '0') ;
}
signed main ( ) {
read(n) , read(m) ;
for(int i = 1 ; i <= m ; i ++) {
int x , y ;
read(x) , read(y) ;
f[x][y] = true ;
}
for(int k = 1 ; k <= n ; k ++) {
for(int i = 1 ; i <= n ; i ++) {
for(int j = 1 ; j <= n ; j ++) {
f[i][j] = f[i][j] or (f[i][k] and f[k][j]) ;
}
}
}
for(int i = 1 ; i <= n ; i ++) {
bool sum = 1 ;
for(int j = 1 ; j <= n ; j ++) {
if(i == j) continue ;
else sum = sum and (f[i][j] or f[j][i]) ;
}
ans += sum ;
}
write(ans) ;
putchar('\n') ;
return 0 ;
}