백준 2610 회의준비
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX_V = 100;
const ll INF = 987654321;
int V;
ll adj[MAX_V][MAX_V];
void floyd() {
for (int i = 0; i < V; ++i) {
adj[i][i] = 0LL;
}
for (int k = 0; k < V; ++k) {
for (int i = 0; i < V; ++i) {
for (int j = 0; j < V; ++j) {
adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
for (int i = 0; i < MAX_V; ++i) {
for (int j = 0; j < MAX_V; ++j) {
adj[i][j] = INF;
}
}
int M;
cin >> V >> M;
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
adj[a - 1][b - 1] = min(adj[a - 1][b - 1], 1LL);
adj[b - 1][a - 1] = min(adj[b - 1][a - 1], 1LL);
}
floyd();
int groupCnt = 0;
int group[MAX_V];
ll maxTime[MAX_V];
for (int i = 0; i < MAX_V; ++i) {
group[i] = maxTime[i] = -1;
}
for (int i = 0; i < V; ++i) {
if (group[i] == -1) {
groupCnt++;
group[i] = groupCnt;
}
for (int j = 0; j < V; ++j) {
if (adj[i][j] < INF) {
group[j] = group[i];
maxTime[i] = max(maxTime[i], adj[i][j]);
}
}
}
cout << groupCnt << "\n";
vector<int> vec;
for (int n = 1; n <= groupCnt; ++n) {
int minPerson;
ll minTime = INF;
for (int i = 0; i < V; ++i) {
if (group[i] != n) continue;
if (minTime > maxTime[i]) {
minTime = maxTime[i];
minPerson = i;
}
}
vec.push_back(minPerson);
}
sort(vec.begin(), vec.end());
for (int i = 0; i < vec.size(); ++i)
cout << vec[i]+1 << "\n";
return 0;
}