This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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(600, -1);
vector<bool> cn(600, 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;
break;
}
//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 0;
return dp[value] = ans;
}
void solve(ll _) {
ll g, n, m; cin>>g>>n>>m;
vector<vector<ll> > graph(600 + 5);
vector<ll> rev(600 + 5);
vector<vector<ll> > ind(600 + 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 (stderr)
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;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |