# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1092992 | Jakub_Wozniak | Village (BOI20_village) | C++17 | 2 ms | 2792 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define nd second
#define st first
typedef pair<ll, ll> pii;
const int maxn = (1e+5)+9;
vector <ll> t[maxn];
ll siz[maxn];
ll dep[maxn];
ll sumdep[maxn];
ll cen = -1;
ll dp[maxn][2];
ll N;
void DFS(int v , int o)
{
ll ind = -1;
ll p , res = 0; bool B = 0; ll mini = (1e+18);
for(int i = 0 ;i < t[v].size();i++)
{
p = t[v][i];
if(p == o)continue;
DFS(p,v);
if(dp[p][1]+2 <= dp[p][0])
{
res += dp[p][1]+2;
B = 1;
}
else
{
res += dp[p][0];
if(dp[p][1]+1-dp[p][0] < mini)ind = p;
mini = min(dp[p][1]+2-dp[p][0] , mini);
}
}
dp[v][1] = res;
if(B == 0)
{
res += mini;
}
dp[v][0] = res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll A , B;
cin >> N;
for(int i = 0 ;i < N-1 ; i++)
{
cin >> A >> B;
t[A].push_back(B);
t[B].push_back(A);
}
if(N == 2)
{
cout << 2 << ' ' << 2 << '\n';
cout << 2 << ' ' << 1 << '\n';
cout << 2 << ' ' << 1 << '\n';
return 0;
}
dep[1] = 0;
DFS(1,-1);
cout << dp[1][0] << ' ' << 1 << '\n';
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... |