# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
161079 | Akashi | Mousetrap (CEOI17_mousetrap) | C++14 | 1132 ms | 158688 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int lim = 1e6 + 5;
int n, t, m;
int w[lim], h[lim], TT[lim];
vector <int> v[lim];
void dfs(int nod = t, int papa = 0){
bool frunza = true;
int Max = 0, Max2 = 0;
for(auto it : v[nod]){
if(papa == it) continue ;
frunza = false;
TT[it] = nod;
w[it] = w[nod];
h[it] = h[nod] + 1;
if(nod != t) w[it] = w[it] + (v[nod].size() - 2);
dfs(it, nod);
if(w[it] > Max) Max2 = Max, Max = w[it];
else if(w[it] > Max2) Max2 = w[it];
}
if(frunza) w[nod] = w[nod] + h[nod];
else{
if(Max2 == 0) w[nod] = w[nod] + h[nod] + 1;
else w[nod] = Max2;
}
}
inline bool check(int tmp){
int cnt = 0;
for(int nod = m, nr = 0, Last = 0; nod != t ; Last = nod, nod = TT[nod], ++nr){
int aux = 0;
for(auto it : v[nod]){
if(it == TT[nod] || it == Last) continue ;
if(w[it] - h[nod] - (nod != m) + cnt > tmp) ++aux;
}
cnt = cnt + aux;
if(cnt > nr + 1) return 0;
}
if(cnt > tmp) return 0;
return 1;
}
int main()
{
// freopen("1.in", "r", stdin);
scanf("%d%d%d", &n, &t, &m);
int x, y;
for(int i = 2; i <= n ; ++i){
scanf("%d%d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
}
dfs();
int st = 0, dr = 2 * n;
while(st <= dr){
int mij = (st + dr) / 2;
if(check(mij)) dr = mij - 1;
else st = mij + 1;
}
printf("%d", st);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |