标签:模板题 -- mat tin floyd cin gcd inf fine
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <map> #include <iomanip> #include <algorithm> #include <queue> #include <stack> #include <set> #include <vector> //const int maxn = 1e5+5; #define ll long long ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} //const int inf = 0x6fffffff; #define MAX INT_MAX #define FOR(i,a,b) for( int i = a;i <= b;++i) #define bug cout<<"--------------"<<endl using namespace std; bool d[310][310]; int n,m,ans; int main() { ios::sync_with_stdio(false); cin>>n>>m; FOR(i,1,n) d[i][i] = 1; FOR(i,1,m) { int x,y,z; cin>>x>>y; d[x][y] = 1; } FOR(k,1,n) FOR(i,1,n) FOR(j,1,n) d[i][j] |= d[i][k] & d[k][j]; for(int i=1 ; i<=n;++i) { int du = 0; for(int j=1;j<=n;++j) { if(i == j) continue; if(d[i][j] == 1 || d[j][i] == 1) du++; } if(du == n-1) ans++; } cout<<ans<<endl; }
标签:模板题 -- mat tin floyd cin gcd inf fine
原文地址:https://www.cnblogs.com/jrfr/p/11370913.html