제출 #114446

#제출 시각아이디문제언어결과실행 시간메모리
114446E869120친구 (IOI14_friend)C++14
27 / 100
5 ms2816 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; vector<int> G[100009]; int A[100009]; int dp[100009][2][2], ty[100009]; void dfs(int pos) { // 1 個目: 0 = 白, 1 = 黒 2 個目: 0 = すべて白、1 = 1 個以上黒 for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]); // dp[0][0] を求める for (int to : G[pos]) { if (ty[to] == 1 || ty[to] == 2) dp[pos][0][0] += max({dp[to][0][0], dp[to][1][0]}); else dp[pos][0][0] += max({dp[to][0][0], dp[to][0][1], dp[to][1][0], dp[to][1][1]}); } // dp[0][1] を求める for (int to : G[pos]) { if (ty[to] == 0 || ty[to] == 2) dp[pos][0][1] += max({dp[to][0][0], dp[to][0][1]}); else dp[pos][0][1] += max({dp[to][0][0], dp[to][0][1], dp[to][1][0], dp[to][1][1]}); } // dp[1][0] を求める if (ty[pos] == 0) { dp[pos][1][0] = A[pos]; for (int to : G[pos]) { if (ty[to] == 2) dp[pos][1][0] += max({dp[to][0][0]}); if (ty[to] == 1) dp[pos][1][0] += max({dp[to][0][0], dp[to][1][0]}); if (ty[to] == 0) dp[pos][1][0] += max({dp[to][0][0], dp[to][0][1]}); } } // dp[1][1] を求める dp[pos][1][1] = A[pos]; for (int to : G[pos]) { if (ty[to] == 0 || ty[to] == 2) dp[pos][1][1] += max({dp[to][0][0], dp[to][0][1]}); else dp[pos][1][1] += max({dp[to][0][0], dp[to][0][1], dp[to][1][0], dp[to][1][1]}); } } int findSample(int n,int confidence[],int host[],int protocol[]){ for (int i = 0; i < n; i++) A[i] = confidence[i]; for (int i = 1; i < n; i++) ty[i] = protocol[i]; for (int i = 1; i < n; i++) G[host[i]].push_back(i); dfs(0); //for (int i = 0; i < n; i++) cout << dp[i][0][0] << " " << dp[i][0][1] << " "<< dp[i][0][2] << " " << dp[i][0][3] << endl; return max({dp[0][0][0], dp[0][0][1], dp[0][1][0], dp[0][1][1]}); }

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

friend.cpp: In function 'void dfs(int)':
friend.cpp:10:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]);
                  ~~^~~~~~~~~~~~~~~
#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...