#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1e9 //๋ฌดํ๋๋ฅผ ์๋ฏธํ๋ ๊ฐ์ผ๋ก 10์ต์ ์ง์
using namespace std;
int N, M; //N=์ ์ ์ ์, M=์น๊ตฌ ๊ด๊ณ ์
int graph[101][101];
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++) {
for (int b = 1; b <= N; b++) {
if (a == b) graph[a][b] = 0; //์๊ธฐ ์์ ์ผ๋ก ํตํ๋ ๊ฒ์ 0
}
}
for (int i = 1; i <= M; i++) { //์น๊ตฌ ๊ด๊ณ ์
๋ ฅ. ํ๋ค๋ฆฌ์ฉ ๊ฑด๋๋ 1์ฉ ์ฆ๊ฐ
int a, b; cin >> a >> b;
graph[a][b] = 1;
graph[b][a] = 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]);
}
}
}
vector<int>kevin(N+1); //์ผ๋น๋ฒ ์ด์ปจ ์ ๋ณด๋ฅผ ๋ด๋ ํ
์ด๋ธ
kevin[0] = INF;
for (int a = 1; a <= N; a++) {
for (int b = 1; b <= N; b++) {
if(graph[a][b]==INF)continue;
kevin[a] += graph[a][b]; //๊ฐ ์ฌ๋๋ง๋ค ๋ค๋ฅธ์ฌ๋์๊ฒ ๊ฐ์ ์๋ ๋ชจ๋ ์ต๋จ๊ฒฝ๋ก๋ฅผ ๋ํด์ค๋ค.
}
}
int min_index = min_element(kevin.begin(), kevin.end()) - kevin.begin(); //์ผ๋น๋ฒ ์ด์ปจ ์๊ฐ ๊ฐ์ฅ ์ ์ ์ฌ๋์ ์ถ๋ ฅํ๋ค.
cout << min_index;
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 14241๋ฒ - ์ฌ๋ผ์ ํฉ์น๊ธฐ (0) | 2021.11.06 |
---|---|
[๋ฐฑ์ค,c++] 1406๋ฒ - ์๋ํฐ (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 13913๋ฒ - ์จ๋ฐ๊ผญ์ง4 (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 1377๋ฒ - ๋ฒ๋ธ ์ํธ (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 1371๋ฒ - ๊ฐ์ฅ ๋ง์ ๊ธ์ (0) | 2021.11.05 |
[๋ฐฑ์ค,c++] 11497๋ฒ - ํต๋๋ฌด ๊ฑด๋๋ฐ๊ธฐ (0) | 2021.11.05 |
๋๊ธ