四大文化赛道完整展开
03-execution/run-002/source-snapshot/main.cpp
main.cpp
站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。
文件类型.cpp
10-cases/s2-jh-03-propagation-sim/03-execution/run-002/source-snapshot/main.cpp
#include <deque>
#include <iostream>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, start;
if (!(cin >> n >> m >> start)) {
return 0;
}
vector<vector<int>> graph(n + 1);
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
vector<int> days(n + 1, -1);
deque<int> q;
days[start] = 0;
q.push_back(start);
while (!q.empty()) {
int node = q.front();
q.pop_front();
for (int nxt : graph[node]) {
if (days[nxt] != -1) {
continue;
}
days[nxt] = days[node] + 1;
q.push_back(nxt);
}
}
int total_days = 0;
int unreached = 0;
for (int i = 1; i <= n; ++i) {
if (days[i] == -1) {
++unreached;
} else if (days[i] > total_days) {
total_days = days[i];
}
}
cout << "total_days=" << total_days << "\n";
cout << "days=";
for (int i = 1; i <= n; ++i) {
if (i > 1) {
cout << ' ';
}
cout << days[i];
}
cout << "\n";
cout << "unreached=" << unreached << "\n";
return 0;
}