#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 9223372036854775807
vector<vector<int>> adj2[100];
set<int> adj[100];
int ans[100];
bool v[100];
bool cyc(int x) {
if(v[x]) return true;
v[x] = 1;
for(int i : adj[x]) {
if(cyc(i)) return true;
}
v[x] = 0;
return false;
}
int dp(int x) {
if(x == 0 || x == 1) return 1;
if(ans[x] != -1) return ans[x];
ans[x] = INF;
for(vector<int> v : adj2[x]) {
int tmp = 0;
for(int i : v) {
tmp += dp(i);
}
ans[x] = min(ans[x], tmp);
}
return ans[x];
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int g, n, m, x, y, a;
cin >> g >> n >> m;
for(int i = 0; i < n; i++) {
cin >> x >> a;
vector<int> tmp;
for(int j = 0; j < a; j++) {
cin >> y;
adj[x].insert(y);
tmp.push_back(y);
}
adj2[x].push_back(tmp);
}
memset(ans, -1, sizeof(ans));
for(int i = 0; i < n; i++) {
memset(v, 0, sizeof(v));
if(cyc(i)) ans[i] = -2;
}
for(int i = 2; i < g; i++) {
if(dp(i) == -2) cout << "YES\n";
else cout << "NO " << dp(i) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |