답안 #845291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845291 2023-09-06T13:01:28 Z vjudge1 Birmingham (COCI20_birmingham) C++11
15 / 70
336 ms 524288 KB
#include <bits/stdc++.h>
#define lg(a) (31 - __builtin_clz((a)))
// #define endl ("\n")
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define vi vector<int>
#define st first
#define nd second
#define all(aa) aa.begin(), aa.end()
#define rall(aa) aa.rbegin(), aa.rend()
#define forn(i, n) for(int i=0;i<n;i++)
#define trav(e, x) for(auto& e:x)
#define until(n, v) (int) (lower_bound(v.begin(), v.end(), n)-v.begin()) //# of elements < n
#define after(n, v) (int) (v.end()-upper_bound(v.begin(), v.end(), n))   //# of elements > n
#define sameas(n, v) (int) (upper_bound(v.begin(), v.end(), n) - lower_bound(v.begin(), v.end(), n)) //# of elements ==n
typedef long long ll;
using namespace std;
/*

*/

int k;
vector<vector<int>> edges;
vector<int> vis;
vector<int> ans;

void bfs(int node, int d, priority_queue<pair<int, int>> next){
	// cout<<"ENTERED BFS AT NODE: "<<node << " DISTANCE: "<< -d<<endl;
	vis[node] = 1;
	ans[node] = -d;
	for(auto e : edges[node]){
		if(vis[e]==0){
			next.push(mp(d-1, e));
		}
	}
	if(next.size()==0) return;
	while(vis[next.top().second] and next.size()!=0) next.pop();
	if(next.size()==0) return;
	pair<int, int> p = next.top();
	next.pop();
	bfs(p.second, p.first, next);
}


void solve(){
	int n, m, q; cin>>n>>m>>q>>k;
	edges.resize(n+1);
	vis.resize(n+1);
	for(auto &e : vis) e = 0;
	ans.resize(n+1);
	for(int i=0;i<q;i++){
		int a; cin>>a;
		edges[n].pb(a-1);
	}
	
	for(int i=0;i<m;i++){
		int a, b; cin>>a>>b;
		edges[a-1].pb(b-1);
		edges[b-1].pb(a-1);
	}
	// for(int i=0;i<=n;i++){
	// 	cout<<endl<<i<<"E ";
	// 	for(auto e : edges[i]) cout<<e<<' ';
	// }
	priority_queue<pair<int,int>> next;
	bfs(n, 1, next);
	for(int i=0;i<n;i++){
		cout<<(ans[i]+k-1)/k<<' ';
	}


}

int main(){
	int test; 
    // cin >> test;
    test =1;
   	while (test--){
		solve();
    }
}



# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 326 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 330 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 336 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 305 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 308 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 319 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 325 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -