이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <climits>
#include <functional>
#include<cstdlib>
//#include "arc.h"
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long LL;
const int MAXN = 5e3 + 11;
using ll = long long;
typedef vector<int> lnum;
const int base = 1e9;
const ll mod1 = 1e9 + 7;
const ll mod2 = 1000000021;
const ll P = 31;
/*
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if ((name.size())) {
freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
freopen((name + ".out").c_str(), "w", stdout);
}
}
*/
int n;
vector<int> adj[MAXN];
vector<int> lst[MAXN];
bool used[MAXN];
int sz = 0;
ll num[MAXN];
ll ans = 1e18;
void calc(int v, int p)
{
sz++;
ll sum = 0;
for (auto u : adj[v])
{
if (u == p)
continue;
calc(u, v);
sum += num[u];
}
num[v] = sum + 1;
}
void build(int v, int p)
{
used[v] = true;
queue<int> q;
q.push(v);
while (!q.empty())
{
int x = q.front();
q.pop();
for (auto u : lst[x])
{
if (used[u])
continue;
adj[u].push_back(x);
adj[x].push_back(u);
used[u] = true;
q.push(u);
}
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
//setIO("time");
cin >> n;
for (int i = 1; i <= n; i++)
{
int k;
cin >> k;
for (int j = 0; j < k; j++)
{
int v;
cin >> v;
lst[v].push_back(i);
}
}
for (int root = 1; root <= n; root++)
{
for (int i = 1; i <= n; i++)
{
adj[i].clear();
used[i] = num[i] = 0;
sz = 0;
}
build(root, root);
calc(root, root);
ll curr = 0;
for (int i = 1; i <= n; i++)
curr += num[i];
if (sz == n)
ans = min(ans, curr);
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'int main()':
bosses.cpp:122:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
122 | used[i] = num[i] = 0;
| ~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |