답안 #845323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845323 2023-09-06T13:10:12 Z vjudge1 Birmingham (COCI20_birmingham) C++11
0 / 70
400 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);
	// binary search to min a s.t. a(a+1)k/2 >= ans[i];
	for(auto e : ans){
		int l = 0, r= n+1, o=0;
		while(l<r){
			int mid = (l+r)/2;
			if(mid*(mid+1)*k/2 < e){
				l = mid+1;
			}
			else if(mid*(mid+1)*k/2 >= e){
				o = mid;
				r = mid;
			}
		}
		cout<<o<<' ';
	}


}

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



# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 352 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 400 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 344 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 356 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 349 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 352 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 369 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -