답안 #1055918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055918 2024-08-13T06:33:28 Z 김은성(#11066) Summer Driving (CCO24_day1problem3) C++17
1 / 25
267 ms 185812 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[1000009];
int par[1000009], depth[1000009];
vector<int> child[1000009];
int pos[1000009];
void settree(int v){
	for(int u: graph[v]){
		if(par[v] == u)
			continue;
		par[u] = v;
		child[v].push_back(u);
		depth[u] = depth[v] + 1;
		settree(u);
	}
}
int main(){
	int n, r, a, b, i, u, v;
	scanf("%d %d %d %d", &n, &r, &a, &b);
	for(i=1; i<n; i++){
		scanf("%d %d", &u, &v);
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	settree(r);
	int k, l;
	if(a >= n){
		pos[min(n, b+1)]--;
		pos[0]++;
	}
	for(k=1; a*k<n; k++){
		if(a*k + k*b + a >= n){
			pos[min(n, a*k + k*b + b + 1)]--;
			pos[max(n-a, a*k-b)]++;
		}
		pos[min(n, a*k + (k-1)*b)]--;
		pos[max(0, a*k-b)]++;
	}
	for(i=1; i<n; i++){
		pos[i] += pos[i-1];
	}
	for(i=1; i<=n; i++){
		if(pos[depth[i]] > 0){
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:26:9: warning: unused variable 'l' [-Wunused-variable]
   26 |  int k, l;
      |         ^
Main.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d %d %d %d", &n, &r, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 65620 KB Output is correct
2 Correct 137 ms 65300 KB Output is correct
3 Correct 151 ms 66020 KB Output is correct
4 Correct 163 ms 68504 KB Output is correct
5 Correct 19 ms 47200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 93112 KB Output is correct
2 Correct 215 ms 92964 KB Output is correct
3 Correct 183 ms 92852 KB Output is correct
4 Correct 158 ms 92800 KB Output is correct
5 Correct 185 ms 93712 KB Output is correct
6 Correct 206 ms 95128 KB Output is correct
7 Correct 209 ms 95164 KB Output is correct
8 Correct 199 ms 95356 KB Output is correct
9 Runtime error 267 ms 185812 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 47452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 47452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 53340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 47452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 65620 KB Output is correct
2 Correct 137 ms 65300 KB Output is correct
3 Correct 151 ms 66020 KB Output is correct
4 Correct 163 ms 68504 KB Output is correct
5 Correct 19 ms 47200 KB Output is correct
6 Correct 187 ms 93112 KB Output is correct
7 Correct 215 ms 92964 KB Output is correct
8 Correct 183 ms 92852 KB Output is correct
9 Correct 158 ms 92800 KB Output is correct
10 Correct 185 ms 93712 KB Output is correct
11 Correct 206 ms 95128 KB Output is correct
12 Correct 209 ms 95164 KB Output is correct
13 Correct 199 ms 95356 KB Output is correct
14 Runtime error 267 ms 185812 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -