結果
| 問題 |
No.2532 Want Play More
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2023-11-03 22:12:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 279 ms / 2,000 ms |
| コード長 | 1,941 bytes |
| コンパイル時間 | 4,260 ms |
| コンパイル使用メモリ | 254,052 KB |
| 最終ジャッジ日時 | 2025-02-17 18:26:09 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
int main(){
int n; cin >> n;
vector ikeru(n, vector<int>(0));
rep(i,0,n-1){
int a, b; cin >> a >> b;
a--; b--;
ikeru[a].push_back(b);
ikeru[b].push_back(a);
}
vector<int> c(n);
auto dfs = [&](auto self, int i, int p) -> void {
for (int j: ikeru[i]){
if (j == p) continue;
c[j] = c[i] ^ 1;
self(self, j, i);
}
};
dfs(dfs, 0, -1);
vector<int> dp1(n);
vector<int> dp2(n);
auto dfs2 = [&](auto self, int i, int p) -> void {
if (c[i] == 0){
dp2[i] = 1e9;
}else{
dp1[i] = 1e9;
}
for (int j: ikeru[i]){
if (j == p) continue;
self(self, j, i);
if (c[i] == 0){
chmax(dp1[i], dp1[j] + 1);
chmin(dp2[i], dp2[j] + 1);
}else{
chmax(dp2[i], dp2[j] + 1);
chmin(dp1[i], dp1[j] + 1);
}
}
if (dp1[i] == 1e9) dp1[i] = 0;
if (dp2[i] == 1e9) dp2[i] = 0;
};
dfs2(dfs2, 0, -1);
cout << dp1[0] << endl;
cout << dp2[0] << endl;
}
shobonvip