// Copyright © 2021 ์์ฃผํ. All rights reserved.
// ํ๋ก์ด๋-์์ฌ ์๊ณ ๋ฆฌ์ฆ
// https://www.acmicpc.net/problem/10159
// BOJ10159 ์ ์ธ
#include <iostream>
#define INF 1e9 //๋ฌดํ๋๋ฅผ ์๋ฏธํ๋ ๊ฐ์ผ๋ก 10์ต์ ์ง์
using namespace std;
int N, M; //N=๋ฌผ๊ฑด์ ๊ฐ์, M=๋ฌผ๊ฑด ์์ ๊ฐ์
int graph[101][101];
int ans[101] = { 0, }; //๋น๊ต๊ฒฐ๊ณผ๋ฅผ ์์์๋ ๋ฌผ๊ฑด ๊ฐฏ์๋ฅผ ์ ์ฅํ๋ ํ
์ด๋ธ
int main() {
cin >> N >> M;
for (int i = 0; i < 101; i++) {
fill(graph[i], graph[i] + 101, INF);
}
for (int a = 1; a<= N; a++) { //์๊ธฐ ์์ ๊ณผ ๋น๊ตํ๋ ๊ฒฝ์ฐ๋ 0์ผ๋ก ์ค์
for (int b = 1; b <= N; b++) {
if (a == b) graph[a][b] = 0;
}
}
for (int i = 1; i <= M; i++) { //๋น๊ต ๊ฒฐ๊ณผ ์
๋ ฅ
int a, b; cin >> a >> b;
graph[a][b] = 1;
}
for (int k = 1; k <= N; k++) { //ํ๋ก์ด๋-์์ฌ ์๊ณ ๋ฆฌ์ฆ ์ํ
for (int a = 1; a <= N; a++) {
for (int b = 1; b <= N; b++) {
graph[a][b] = min(graph[a][b], graph[a][k] + graph[k][b]);
}
}
}
for (int a = 1; a <= N; a++) { //์ถ๋ ฅ
for (int b = 1; b <= N; b++) {
if (graph[a][b] == INF&&graph[b][a]==INF) ans[a]++; //N๋ฒ์งธ ๋ฌผ๊ฑด์ด ๋ค๋ฅธ๋ฒํธ์ ์๋ก ๋น๊ต๊ฐ ๋ถ๊ฐ๋ฅํ ๋ ์นด์ดํฐ๋ฅผ ์ธ์ค๋ค.
}
cout << ans[a] << "\n";
}
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 1032๋ฒ - ๋ช ๋ น ํ๋กฌํํธ (0) | 2021.10.16 |
---|---|
[๋ฐฑ์ค,c++] 1026๋ฒ - ๋ณด๋ฌผ (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 10174๋ฒ - ํฐ๋ฆฐ๋๋กฌ (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 1015๋ฒ - ์์ด ์ ๋ ฌ (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 1012๋ฒ - ์ ๊ธฐ๋ ๋ฐฐ์ถ (0) | 2021.10.16 |
[๋ฐฑ์ค,c++] 1010๋ฒ - ๋ค๋ฆฌ ๋๊ธฐ (0) | 2021.10.16 |
๋๊ธ