# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1208925 | _Temirhan | Power Plant (JOI20_power) | C++20 | 2 ms | 4936 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
#define sz(x) x.size()
#define F first
#define S second
#define pb push_back
#define nl '\n';
void Debug()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int N = 2e5 + 1;
const int inf = 1e9 + 1;
const int INF = 1e18;
const int mod = 1e9 + 7;
int T = 1, n, p[N], cnt, ch;
string s;
vector< int >g[N];
void DFS( int v, int pr )
{
for( int to: g[v] )
if( to != pr )
{
DFS(to, v);
p[v] += p[to];
}
}
void dfs( int v, int pr )
{
int res = 0;
for( int to: g[v] )
if( to != pr )
{
dfs(to, v);
if( p[to] )
++res;
}
if( v == 1 && res >= 3 )
ch = 1;
if( v > 1 && p[1] - p[v] > 0 && res >= 2 )
ch = 1;
}
signed main()
{
// Debug();
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >>n;
for( int i = 1, u, v; i < n; ++i )
{
cin >>u >>v;
g[u].pb( v );
g[v].pb( u );
}
cin >>s;
for( int i = 0; i < n; ++i )
if( s[i] == '1' )
{
++cnt;
p[i + 1] = 1;
}
DFS(1, 0);
dfs(1, 0);
if( ch )
cout <<3;
else
cout <<min(2ll, cnt);
}
Compilation message (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... |