제출 #1127360

#제출 시각아이디문제언어결과실행 시간메모리
1127360Peter2017Power Plant (JOI20_power)C++20
0 / 100
4 ms4936 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define pii pair<int,int> #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define mem(a, b) memset(a, b, sizeof(a)) #define name "test" using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;} template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;} int n; int ans; int f[N]; string s; vector<int> adj[N]; void load(){ cin.tie(0)->sync_with_stdio(0); if (fopen(name".inp", "r")){ freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } } void input(){ cin >> n; for (int i = 1; i < n; i++){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } cin >> s; s = " " + s; } void dfs(int u, int pre){ int sum = 0; int x = (s[u] == '1'); f[u] = x; for (int v : adj[u]) if (v != pre){ dfs(v, u); maxi(ans, f[v] + x); sum += f[v]; } maxi(ans, f[u]); maxi(f[u], sum - x); } void solve(){ dfs(1, 0); cout << ans; } int main(){ load(); input(); solve(); }

컴파일 시 표준 에러 (stderr) 메시지

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