이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = (l); i < r; ++i)
#define NN
#define M 1000000007 // 998244353
vector<ll> availWhenPlaced[5010];
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
G(n)
F(i, 1, n+1) {
G(k) while(k--) {
G(t) availWhenPlaced[t].push_back(i);
}
}
ll ans = n*n;
F(root, 1, n+1) {
vector<bool> vis(n+1); vector<ll> q{root}, nq; vis[root] = 1;
ll tans = 0;
for (ll dep = 1; q.size(); swap(q, nq), nq.clear(), dep++) {
for (const auto &x: q) {
tans += dep;
for (const auto &y: availWhenPlaced[x]) if (!vis[y]) {
vis[y] = 1;
nq.push_back(y);
}
}
}
if (count(A(vis), true) == n) ans = min(ans, tans);
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |