Submission #1208925

#TimeUsernameProblemLanguageResultExecution timeMemory
1208925_TemirhanPower Plant (JOI20_power)C++20
0 / 100
2 ms4936 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)

power.cpp: In function 'void Debug()':
power.cpp:19:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |                 freopen("input.txt", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
power.cpp:20:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |                 freopen("output.txt", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...