题目链接
题目:
代码
#include <bits/stdc++.h>
inline int read(){char c = getchar();int x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
const int N = 1e6 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const unsigned long long mod = 998244353;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int Map[100][100],n;
n = read();
for(int i = 0;i < n;i++)
for(int j = 0;j < n;j++)
Map[i][j] = read();
for(int k = 0;k < n;k++)
for(int i = 0;i < n;i++)
for(int j = 0;j < n;j++)
if(Map[i][k] && Map[k][j])
Map[i][j] = 1;//floyd算法变形,如果i到k有路,而且k到j有路,那么i到j也有路
for(int i = 0,sum = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
if(i != j && Map[i][j])
sum++;
if(sum == n-1) cout << i;
sum = 0;
}
}