signedmain(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int a[10] {}; for (int i = 0; i < 4; i++) { int x; std::cin >> x; a[x]++; if (a[x] == 2) { std::cout << x << "\n"; break; } }
signedmain(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, k, s; std::cin >> n >> m >> k >> s;
std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::vector<std::vector<int>> g(n); for (int i = 0; i < m; i++) { int u, v; std::cin >> u >> v; u--, v--; g[u].emplace_back(v); g[v].emplace_back(u); }
std::vector dist(n, std::vector<int>(k + 1)); for (int i = 1; i <= k; i++) { auto bfs = [&](int u) { std::queue<int> q; for (int i = 0; i < n; i++) { dist[i][u] = inf; if (a[i] == u) { q.push(i); dist[i][u] = 0; } }
while (!q.empty()) { int t = q.front(); q.pop();
for (auto x : g[t]) { if (dist[x][u] > dist[t][u] + 1) { dist[x][u] = dist[t][u] + 1; q.push(x); } } } }; bfs(i); }
for (int i = 0; i < n; i++) { std::sort(dist[i].begin() + 1, dist[i].begin() + k + 1); int ans = 0; for (int j = 1; j <= s; j++) { ans += dist[i][j]; } std::cout << ans << " \n"[i == n - 1]; } return0; }