#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fastIO cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
#define mid ((l + r) / 2)
#define lChild ((index * 2) + 1)
#define rChild ((index * 2) + 2)
using namespace std;
struct edge {
ll u, c;
};
vector<ll> dp(1e6 + 5, -1);
vector<bool> cn(1e6 + 5, 0);
ll get(vector<vector<ll> >& graph, vector<vector<ll> >& ind, vector<ll>& num, ll startIndex, ll p, ll value) {
// cout<<startIndex<<endl;
ll ans = num[startIndex];
bool can = true;
for(auto el : graph[startIndex]) {
if(el == value) {
can = false;
continue;
}
//cout<<" => "<<el<<endl;
if(dp[el] == -1) {
ll mn = LLONG_MAX;
for (auto it: ind[el]) {
mn = min(mn, get(graph, ind, num, it, startIndex, el));
}
dp[el] = mn;
}
ans += dp[el];
}
// cout<<"dp["<<value<<"] ="<<ans<<endl;
if(!can) return -1;
return dp[value] = ans;
}
void solve(ll _) {
ll g, n, m; cin>>g>>n>>m;
vector<vector<ll> > graph(1e6 + 5);
vector<ll> rev(1e6 + 5);
vector<vector<ll> > ind(1e6 + 5);
vector<bool> cn(6000, false);
ll t = -1;
vector<ll> num(n);
for(int i = 0; i < n; i++) {
ll a; cin>>a;
ll k; cin>>k;
ind[a].push_back(i);
rev[i] = a;
ll w = 0;
bool can = true;
bool has = false;
for(int j = 0; j < k; j++) {
ll x; cin>>x;
if(x == 1 || x == 0) {
w += 1;
continue;
}
can = false;
if(x == a) has= true;
graph[i].push_back(x);
}
cn[a] = cn[a] | !has;
// cout<<"a: "<<w<<endl;
num[i] = w;
}
for(int i = 0; i < n; i++) {
get(graph, ind, num, i , -1, rev[i]);
}
for(int i = 2; i <= g; i++) {
if(!cn[i]) cout<<"YES"<<endl;
else cout<<"NO "<<dp[i]<<endl;
}
}
int main() {
fastIO
//freopen("file.in", "r", stdin);
//freopen("file.out", "w", stdout);
ll t = 0; solve(t);
}
Compilation message
Viruses.cpp: In function 'void solve(long long int)':
Viruses.cpp:76:14: warning: variable 'can' set but not used [-Wunused-but-set-variable]
76 | bool can = true;
| ^~~
Viruses.cpp:67:8: warning: unused variable 't' [-Wunused-variable]
67 | ll t = -1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
129 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
129 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
63068 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
129 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
129 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |