이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 1e5 + 1;
void solve() {
int n;
cin >> n;
bool was[n];
vt<int> v[n];
for(int i = 0; i < n; i++){
int k;
cin >> k;
for(int j = 0, t; j < k; j++) {
cin >> t;
t--;
v[t].pb(i);
}
}
int sum = n * n;
for(int i = 0; i < n; i++){
memset(was, 0, sizeof was);
queue<pii> q;
q.push({i, 1});
was[i] = 1;
int ans = 0, cnt = 0;
while(!q.empty()){
pii nw = q.front();
q.pop();
ans += nw.ss;
cnt++;
for(auto j : v[nw.ff]){
if(!was[j])was[j] = 1, q.push({j, nw.ss + 1});
}
}
if(cnt == n)sum = min(sum , ans);
}
cout << sum;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 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... |