Submission #1037356

#TimeUsernameProblemLanguageResultExecution timeMemory
1037356onbertFriend (IOI14_friend)C++17
58 / 100
29 ms12036 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, a[maxn]; vector<int> adj[maxn][3]; int dp[maxn][2]; void dfs(int u) { for (int i=0;i<=2;i++) for (int v:adj[u][i]) dfs(v); int pt1 = 0, pt2 = 0, cur = 0; for (int v:adj[u][0]) cur += dp[v][1]; for (int v:adj[u][1]) cur += dp[v][0]; for (int v:adj[u][2]) cur += dp[v][0]; int val = cur, mx = 0; for (int v:adj[u][0]) { while (pt1<adj[u][1].size() && adj[u][1][pt1] < v) cur += dp[adj[u][1][pt1]][1] - dp[adj[u][1][pt1]][0], pt1++; while (pt2<adj[u][2].size() && adj[u][2][pt2] < v) mx = max(dp[adj[u][2][pt2]][1] - dp[adj[u][2][pt2]][0], mx), pt2++; val = max(cur + mx, val); cur += dp[v][0] - dp[v][1]; } while (pt1<adj[u][1].size()) cur += dp[adj[u][1][pt1]][1] - dp[adj[u][1][pt1]][0], pt1++; while (pt2<adj[u][2].size()) mx = max(dp[adj[u][2][pt2]][1] - dp[adj[u][2][pt2]][0], mx), pt2++; val = max(cur + mx, val); dp[u][0] = 0; for (int v:adj[u][0]) dp[u][0] += dp[v][1]; for (int v:adj[u][1]) dp[u][0] += dp[v][0]; for (int v:adj[u][2]) dp[u][0] += dp[v][0]; dp[u][1] = a[u]; for (int v:adj[u][0]) dp[u][1] += dp[v][0]; for (int v:adj[u][1]) dp[u][1] += dp[v][1]; for (int v:adj[u][2]) dp[u][1] += dp[v][0]; dp[u][1] = max({val, dp[u][0], dp[u][1]}); } int findSample(int N, int confidence[], int host[], int t[]){ n = N; for (int i=0;i<n;i++) a[i] = confidence[i]; for (int i=1;i<n;i++) adj[host[i]][t[i]].push_back(i); dfs(0); // for (int j=0;j<=1;j++) { // cout << j << endl; // for (int i=0;i<n;i++) cout << dp[i][j] << " "; cout << endl; // } return dp[0][1]; }

Compilation message (stderr)

friend.cpp: In function 'void dfs(int)':
friend.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         while (pt1<adj[u][1].size() && adj[u][1][pt1] < v) cur += dp[adj[u][1][pt1]][1] - dp[adj[u][1][pt1]][0], pt1++;
      |                ~~~^~~~~~~~~~~~~~~~~
friend.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         while (pt2<adj[u][2].size() && adj[u][2][pt2] < v) mx = max(dp[adj[u][2][pt2]][1] - dp[adj[u][2][pt2]][0], mx), pt2++;
      |                ~~~^~~~~~~~~~~~~~~~~
friend.cpp:22:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     while (pt1<adj[u][1].size()) cur += dp[adj[u][1][pt1]][1] - dp[adj[u][1][pt1]][0], pt1++;
      |            ~~~^~~~~~~~~~~~~~~~~
friend.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while (pt2<adj[u][2].size()) mx = max(dp[adj[u][2][pt2]][1] - dp[adj[u][2][pt2]][0], mx), pt2++;
      |            ~~~^~~~~~~~~~~~~~~~~
#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...