結果
| 問題 | No.763 Noelちゃんと木遊び |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-24 10:13:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 1,979 bytes |
| 記録 | |
| コンパイル時間 | 1,855 ms |
| コンパイル使用メモリ | 198,248 KB |
| 実行使用メモリ | 20,212 KB |
| 最終ジャッジ日時 | 2025-11-24 10:13:29 |
| 合計ジャッジ時間 | 4,438 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:63:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:64:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
64 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
bool M1;
#define task "task"
#define bit(x, i) ((x >> i) & 1)
// https://trap.jp/post/1224/
#define FOR1(i, a, b) for(int i = (a), _b = (b); i <= _b; i ++)
#define FOR2(i, a, b, c) for(int i = (a), _b = (b); i <= _b; i += c)
#define FORD1(i, a, b) for(int i = (a), _b = (b); i >= _b; i --)
#define FORD2(i, a, b, c) for(int i = (a), _b = (b); i >= _b; i -= c)
#define overload4(a, b, c, d, name, ...) name
#define FOR(...) overload4(__VA_ARGS__, FOR2, FOR1)(__VA_ARGS__)
#define FORD(...) overload4(__VA_ARGS__, FORD2, FORD1)(__VA_ARGS__)
#define pb emplace_back
#define pf emplace_front
#define ins emplace
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(), v.end()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
// mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
// ll rand(ll l, ll r) { assert(l <= r); return uniform_int_distribution<ll>(l, r)(rd); }
const int N = 2e5 + 5;
const ll inf = 1e18;
const int mod = 1e9 + 7;
const int base = 31;
int n, dp[N][2];
vector<int> g[N];
void dfs(int u, int p){
dp[u][0] = 1;
for(int v : g[u]) if(v != p){
dfs(v, u);
dp[u][0] += max(dp[v][1], dp[v][0] - 1);
dp[u][1] += max(dp[v][0], dp[v][1]);
}
}
void solve(){
cin>>n;
FOR(i, 1, n - 1){
int u, v; cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
dfs(1, 0);
cout<<max(dp[1][0], dp[1][1]);
}
bool M2;
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin>>tc;
while(tc --) solve();
cerr << "\nMemory: " << abs(&M2-&M1)/1024.0/1024 << " Mb\n";
cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " ms\n";
return 0;
}