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 ll long long
const int N = 2e5 + 5, MOD = 1e9 + 7;
int dist[N];
bool visited[N];
vector<int> adj[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, asd, k;
cin >> n >> m >> asd >> k;
queue<int> q;
for(int i = 0; i < asd; i++)
{
int x;
cin >> x;
dist[x] = 0;
visited[x] = true;
q.push(x);
}
for(int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
while(q.size())
{
auto node = q.front();
q.pop();
for(auto to : adj[node])
{
if(!visited[to])
{
dist[to] = dist[node] + 1;
visited[to] = true;
q.push(to);
}
}
}
for(int i = 1; i <= n; i++)
{
ll l = 0, r = 100000, ans;
// cout << dist[i] << '\n';
while(l <= r)
{
ll mid = (l + r) / 2;
if(dist[i] <= k * (mid * (mid + 1)) / 2)
{
r = mid - 1;
ans = mid;
}
else
{
l = mid + 1;
}
}
cout << ans << " ";
}
}
# | 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... |