제출 #285642

#제출 시각아이디문제언어결과실행 시간메모리
285642ToMmyDong친구 (IOI14_friend)C++11
27 / 100
5 ms3584 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define first X #define second Y #define eb emplace_back #define ALL(i) i.begin(),i.end() #define SZ(i) int(i.size()) #ifdef tmd #define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__); template<typename T> void _do (T &&x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);} template<typename IT> ostream &__printRng (ostream& os, IT bg, IT ed) { for (IT it=bg; it!=ed; it++) { if (it == bg) os << "{" << *it; else os << "," << *it; } return os << "}"; } template<typename T> ostream &operator << (ostream& os, const vector<T> &vec) { return __printRng(os,ALL(vec)); } #else #define debug(...) #endif #include "friend.h" // Find out best sample const int MAXN = 100005; vector<int> edge[MAXN]; void add_edge (int u, int v) { edge[u].eb(v); edge[v].eb(u); } bool vis[MAXN]; int dp[2][MAXN]; void dfs (int nd, int &x, int &y, int &bg, int *cf, int c=0) { bg = max(bg, cf[nd]); if (c) x += cf[nd]; else y += cf[nd]; vis[nd] = true; for (auto v : edge[nd]) { if (!vis[v]) { dfs(v, x, y, bg, cf, c^1); } } } void solve (int nd, int *cf) { vis[nd] = true; dp[1][nd] = cf[nd]; for (int v : edge[nd]) { if (!vis[v]) { solve(v, cf); dp[1][nd] += dp[0][v]; dp[0][nd] += max(dp[0][v], dp[1][v]); } } return; } int findSample(int n,int confidence[],int host[],int p[]){ bool fc = false; for (int i=1; i<n; i++) { if (p[i] == 0) { add_edge(i, host[i]); } else if (p[i] == 1) { for (auto v : edge[host[i]]) { add_edge(v, i); } } else { for (auto v : edge[host[i]]) { add_edge(v, i); } add_edge(i, host[i]); fc = true; } } int tree = 0; for (int i=0; i<n; i++) { if (!vis[i]) { solve(i, confidence); tree += max(dp[0][i], dp[1][i]); } } return tree; int ans = 0; int sz = 0; for (int i=0; i<n; i++) { if (!vis[i]) { int x = 0, y = 0, bg = 0; dfs(i, x, y, bg, confidence, 0); ans += max(x, y); sz+=bg; } } return ans; }

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

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:68:10: warning: variable 'fc' set but not used [-Wunused-but-set-variable]
   68 |     bool fc = false;
      |          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...