이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
int n, a, b, ans = INF, dep[5005];
vi adj[5005];
bool vis[5005];
int bfs(int x) {
queue<int> q; q.push(x);
memset(vis, 0, sizeof vis);
memset(dep, 0, sizeof dep);
vis[x] = 1; dep[x] = 1;
while (!q.empty()) {
int cur = q.front(); q.pop();
for (auto it:adj[cur]) if (!vis[it]) {
q.push(it);
vis[it] = 1; dep[it] = dep[cur] + 1;
}
}
FOR(i, 1, n) if (!vis[i]) return INF;
int res = 0; FOR(i, 1, n) res += dep[i];
return res;
}
int main() {
fastio; cin >> n;
FOR(i, 1, n) {
cin >> a;
while (a--) {
cin >> b;
adj[b].pb(i);
}
}
FOR(i, 1, n) ans = min(ans, bfs(i));
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |