Submission #238526

# Submission time Handle Problem Language Result Execution time Memory
238526 2020-06-11T16:06:15 Z Salito Birmingham (COCI20_birmingham) C++17
0 / 70
247 ms 8056 KB
#include<bits/stdc++.h>
using namespace std;
int const maxn = 100005;

int n,m,q,k;
int a[maxn];
vector<int>v[maxn];

void read()
{
    int i;
	cin>>n>>m>>q>>k;

	for(i=0;i<q;i++)
        cin>>a[i];

    int x,y;
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
}

int ans[maxn];
queue<int>gq;

void dfs(int i, int d, int p)
{
    if(d == 0)return ;

    int j,sz=v[i].size();
    for(j=0;j<sz;j++)
    {
        int nb = v[i][j];
        if(!ans[nb])
        {
            gq.push(nb);
            ans[nb] = ans[p]+1;
            dfs(nb,d-1,p);
        }
    }
}

void bfs_solve()
{
    int i;
    for(i=0;i<q;i++)
    {
        gq.push(a[i]);
        ans[a[i]] = 1;
    }

    while(!gq.empty())
    {
        int t = gq.front();
        gq.pop();
        dfs(t,k*ans[t],t);
    }
}

void print()
{
    int i;
    cout<<ans[1];
    for(i=2;i<=n;i++)
        cout<<" "<<ans[i]-1;
}

int main()
{
    read();

    bfs_solve();

    print();
	return 0;
}
/*

9 9 1 1
8
1 2
1 3
1 5
2 4
5 2
5 6
6 7
8 6
9 6

*/
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 221 ms 7672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 247 ms 8056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 235 ms 7672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 195 ms 7416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 196 ms 7548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 200 ms 7544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 222 ms 7672 KB Output isn't correct
2 Halted 0 ms 0 KB -