이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool tr;
int n, mn = INT_MAX, Sm;
vector<bool> vis;
vector<vector<int>> v, E;
int dfs(int x) {
int sm = 1;
vis[x] = true;
for (auto i : E[x]) {
if (tr || vis[i]) return tr = true, 0;
sm += dfs(i);
}
Sm += sm;
return sm;
}
void f(int x, int rt) {
if (x == rt) f(x + 1, rt);
if (x == n) {
Sm = 0;
tr = false;
vis.assign(n, false);
dfs(rt);
if (!tr && !count(vis.begin(), vis.end(), false)) mn = min(mn, Sm);
return;
}
for (auto i : v[x]) {
E[i].push_back(x);
f(x + 1, rt);
E[i].pop_back();
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
v.assign(n, {});
for (int i = 0; i < n; i++) {
int k;
cin >> k;
while (k--) {
int x;
cin >> x; x--;
v[i].push_back(x);
}
}
E.assign(n, {});
for (int i = 0; i < n; i++) {
f(0, i);
}
cout << mn;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |