Submission #775350

#TimeUsernameProblemLanguageResultExecution timeMemory
775350danikoynovFriend (IOI14_friend)C++14
35 / 100
1 ms468 KiB
#include "friend.h" #include<bits/stdc++.h> using namespace std; // Find out best sample const int maxn = 1010; typedef long long ll; vector < int > adj[maxn]; void add_edge(int v, int u) { adj[v].push_back(u); adj[u].push_back(v); } vector < int > ord; int used[maxn]; void bfs(int v) { queue < int > q; used[v] = 1; q.push(v); while(!q.empty()) { int cur = q.front(); q.pop(); ord.push_back(cur); for (int u : adj[cur]) { if (used[u] == 0) { if (used[cur] == 1) used[u] = 2; else used[u] = 1; q.push(u); } } } } int con[maxn], dp[maxn][2]; void dfs(int v, int p) { dp[v][1] = con[v]; used[v] = 1; for (int u : adj[v]) { if (u == p) continue; dfs(u, v); dp[v][0] += max(dp[u][0], dp[u][1]); dp[v][1] += dp[u][0]; } } int findSample(int n,int confidence[],int host[],int protocol[]) { bool only_my = true, only_we = true; for (int i = 1; i < n; i ++) { if (protocol[i] != 1) only_my = false; if (protocol[i] != 2) only_we = false; } for (int i = 0; i < n; i ++) { con[i] = confidence[i]; } if (only_my) { int ans = 0; for (int i = 0; i < n; i ++) ans += confidence[i]; return ans; } else if (only_we) { int ans = 0; for (int i = 0; i < n; i ++) ans = max(ans, confidence[i]); return ans; } else { for (int i = 1; i < n; i ++) { if (protocol[i] == 0) { add_edge(i, host[i]); } else { assert(0); } /**if (protocol[i] == 2) { for (int u : adj[host[i]]) add_edge(u, i); }*/ } ll ans = 0; for (int i = 0; i < n; i ++) { if (!used[i]) { dfs(i, -1); ans = ans + max(dp[i][0], dp[i][1]); } } return ans; } }

Compilation message (stderr)

friend.cpp: In function 'void dfs(int, int)':
friend.cpp:51:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   51 |         if (u == p)
      |         ^~
friend.cpp:53:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   53 |             dfs(u, v);
      |             ^~~
#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...