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>
#define fff "main"
#define For(i,a,b) for (auto i = a; i < b; ++i)
#define pb push_back
#define en cout << '\n';
using namespace std;
typedef signed long long int ll;
typedef std::vector<ll> vll;
vector<pair<ll,ll> > ct[100001];
ll d[100001];
ll know_first[100001];
ll n,m,q,k;
void spf(){
priority_queue<pair<ll, ll >, vector<pair<ll,ll > >, greater<pair<ll, ll > > >pq;
For (i,1,n+1) {
d[i] = 99999999999;
if (know_first[i]){
d[i] = 0;
pq.push({0,i});
}
}
while (pq.size()) {
ll u = pq.top().second;
ll du = pq.top().first;
pq.pop();
if (du > d[u]) continue;
for (auto f : ct[u]){
ll v = f.second;
ll w = f.first;
if (d[v] > du + w) {
d[v] = du + w;
pq.push({d[v], v});
}
}
}
}
ll sum_to(const ll &x){
return (x * (x + 1)) / 2;
}
int main()
{
// if (fopen(fff".inp","r")) {
// freopen(fff".inp","r",stdin);
// freopen(fff".out","w",stdout);
// }
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> q >> k;
while (q--) {
ll f;
cin >> f;
know_first[f] = 1;
}
while (m--){
ll u, v; cin >> u >> v;
ct[u].pb({1,v});
ct[v].pb({1,u});
}
spf();
vll check;
for (ll i = 0; sum_to(i) <= n / k; ++i){
check.pb(sum_to(i) * k);
}
For (i,1,n+1){
cout << lower_bound(check.begin(),check.end(),d[i]) - check.begin() << ' ';
}
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... |