이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}
//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
vll v[N], g[N];
set<ll> s[N];
ll root;
ll dead[N], c[N], p[N], dp[N], used[N];
void dfs(int u, int e)
{
int flag = 0;
ll sum = 0;
for(auto it : g[u])
{
if(it != e)
{
dfs(it, u);
flag = 1;
sum += dp[it];
}
}
dp[u] = sum + 1;
return;
}
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i ++)
{
int x;
cin >> x;
while(x --)
{
ll o;
cin >> o;
v[o].pb(i);
}
}
ll ans = 1e17;
for(int i = 1; i <= n; i ++)
{
queue<int> q;
for(int i = 1; i <= n; i ++)
used[i] = p[i] = dp[i] = 0,
g[i].clear();
q.push(i);
used[i] = 1;
while(!q.empty())
{
int u = q.front();
q.pop();
for(auto it : v[u])
{
if(used[it])
continue;
q.push(it);
p[it] = u;
used[it] = 1;
}
}
for(int i = 1; i <= n; i++)
{
g[p[i]].pb(i);
g[i].pb(p[i]);
}
dfs(i, 0);
ll res = 0;
for(int i = 1; i <= n; i ++)
res += dp[i];
umin(ans, res);
}
cout << ans;
getchar();
getchar();
return 0;
//ios::sync_with_stdio(false);
//cin.tie(0);
}
컴파일 시 표준 에러 (stderr) 메시지
bosses.cpp: In function 'void dfs(int, int)':
bosses.cpp:40:6: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
int flag = 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... |