제출 #1092992

#제출 시각아이디문제언어결과실행 시간메모리
1092992Jakub_WozniakVillage (BOI20_village)C++17
0 / 100
2 ms2792 KiB
#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) 메시지

Village.cpp: In function 'void DFS(int, int)':
Village.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i = 0 ;i < t[v].size();i++)
      |                    ~~^~~~~~~~~~~~~
Village.cpp:19:8: warning: variable 'ind' set but not used [-Wunused-but-set-variable]
   19 |     ll ind = -1;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...