This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int N = 1e5 + 2;
vector<vector<int> > g(N , vector<int>());
int main() {
#ifdef judge
ifstream cin("input.txt");
#endif // judge
ios_base :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int n , m , que , k;
cin >> n >> m >> que >> k;
queue<int> q;
vector<int> starts(que) , d(n + 1 , 0);
vector<bool> used(n + 1 , false);
for (int i = 0; i < que; i++) {
cin >> starts[i];
q.push(starts[i]);
used[starts[i]] = true;
}
for (int i = 0; i < m; i++) {
int u , v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
while (!q.empty()) {
int v = q.front();
q.pop();
for (int to : g[v]) {
if (!used[to]) {
used[to] = true;
q.push(to);
d[to] = d[v] + 1;
} else if (d[v] + 1 < d[to]) {
q.push(to);
d[to] = d[v] + 1;
}
}
}
auto getDay = [&](int dist) {
int res = 0 , temp = 1;
while (res < dist) {
res += (temp * k);
temp++;
}
return temp - 1;
};
for (int i = 1; i <= n; i++) {
if (d[i] != 0) {
cout << getDay(d[i]) << " ";
} else {
cout << 0 << " ";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |