이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std ;
// Find out best sample
const int N = 100010 ;
int confi[N] ;
int dp [N][2];
vector <int> G[N][2] ;
int go ( int u, int flag ) {
auto &rf = dp[u][flag];
if ( rf!=-1 ) return rf ;
if ( flag ) {
///take
int x = confi[u] ;
for ( auto v:G[u][0] ) x += go( v, 0 ) ;
for ( auto v:G[u][1] ) x += go( v, 1 ) ;
rf = x ;
///dont take
x = 0 ;
int it1 = 0, it2 = 0, rep = 0, rep2 =0 ;
for ( auto v:G[u][0] ) rep += go(v, 1) ;
for ( auto v:G[u][1] ) rep2 += go(v, 0) ;
while ( it1 < G[u][0].size() ) {
while ( it2 < G[u][1].size() && G[u][1][it2] < G[u][0][it1] ) {
rep2 -= go(G[u][1][it2], 0) ;
rep2 += go(G[u][1][it2], 1) ;
it2++ ;
}
x = max ( x, rep2+rep ) ;
rep -= go(G[u][0][it1],1) ;
rep += go(G[u][0][it1],0) ;
it1++ ;
}
rf = max ( rf, x ) ;
}
else {
int x = 0 ;
for ( auto v:G[u][1] ) x += go ( v, 0 ) ;
for ( auto v:G[u][0] ) x += go ( v, 1 ) ;
rf = x ;
}
return rf ;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
if ( protocol[1] == 2 ) return *max_element ( confidence, confidence+n ) ;
for ( int i = 0 ; i < n ; ++i ) confi[i] = confidence[i] ;
for ( int i = 1 ; i < n ; ++i ) G[host[i]][protocol[i]].push_back ( i ) ;
memset ( dp,-1,sizeof dp ) ;
return go(0,1) ;
}
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp: In function 'int go(int, int)':
friend.cpp:30:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while ( it1 < G[u][0].size() ) {
~~~~^~~~~~~~~~~~~~~~
friend.cpp:31:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while ( it2 < G[u][1].size() && G[u][1][it2] < G[u][0][it1] ) {
~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |