#include <algorithm>
#include <iostream>
using namespace std;
int map[101][101];
//floyd-warshall 알고리즘
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M, a, b, ans;
cin >> N;
cin >> M;
for (int i = 0; i < M; i++)
{
cin >> a >> b;
map[a][b] = 1;
map[b][a] = -1;
}
for (int k = 1; k <= N; k++)
{
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
if (map[i][k] == map[k][j] && map[i][k] != 0)
map[i][j] = map[i][k];
}
}
}
for (int i = 1; i <= N; i++)
{
ans = N - 1;
for (int j = 1; j <= N; j++)
{
if (map[i][j] != 0)
ans--;
}
cout << ans << "\n";
}
return 0;
}
플로이드 와샬 알고리즘은 기본적으로 삼중 for문을 돌리므로 O(N^3)의 시간복잡도를 가진다.
여기서는 시간제한이 1초인데 N값이 최대 100이므로 1000000, 즉 100만이 되어 1억을 넘지 않는다.
따라서 1초이내로 구현이 가능하다.