이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000009ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
#ifndef death
#include "friend.h"
#endif
const int N = 1003;
int dp[N][2], a[N];
vector<int> g[N];
void dfs(int v, int p)
{
dp[v][1] = a[v];
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i];
if (to == p)
continue;
dfs(to, v);
dp[v][1] += dp[to][0];
dp[v][0] += dp[to][1];
}
}
int findSample(int n, int confidence[], int host[], int protocol[])
{
int ans = 0;
set<int> type;
for (int i = 1; i < n; i++)
type.insert(protocol[i]);
for (int i = 0; i < n; i++)
a[i] = confidence[i];
if (type.size() == 1)
{
if ((*type.begin()) == 2)
{
sort(confidence, confidence + n);
ans = confidence[n - 1];
}
if ((*type.begin()) == 1)
{
for (int i = 0; i < n; i++)
ans += a[i];
}
else
{
int sum = 0;
for (int i = 0; i < n; i++)
sum += a[i];
for (int i = 1; i < n; i++)
{
g[host[i]].PB(i);
g[i].PB(host[i]);
}
dfs(0, -1);
ans = max(dp[0][1], sum - dp[0][1]);
}
}
return ans;
}
#ifdef death
int main()
{
return 0;
}
#endif
/*
7
5 6 7 1 2 3 4
7
5 6 7 1 2 10 4
7
2 3 4 9 6 7 1
1 2 3 4 9 6 7
*/
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp: In function 'void dfs(int, int)':
friend.cpp:38:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[v].size(); i++)
~~^~~~~~~~~~~~~
# | 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... |