# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
915273 |
2024-01-23T15:22:43 Z |
3as8 |
Viruses (BOI20_viruses) |
C++14 |
|
0 ms |
0 KB |
#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);
vector<bool> is(600, 0);
ll get(vector<vector<ll> >& graph, vector<vector<ll> >& ind, vector<ll>& num, ll startIndex, ll p, ll value) {
// cout<<startIndex<<endl;
if(dp[value] != -1) return dp[value];
if(is[value]) return 0;
ll ans = num[startIndex];
bool can = true;
for(auto el : graph[startIndex]) {
if(el == value) {
can = false;
break;
}
//cout<<" => "<<el<<endl;
is[value] = true;
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;
}
is[value] = false;
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++) {
for(auto& el : is) el = false;
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:80:14: warning: variable 'can' set but not used [-Wunused-but-set-variable]
80 | bool can = true;
| ^~~
Viruses.cpp:102:24: error: cannot bind non-const lvalue reference of type 'std::_Bit_reference&' to an rvalue of type 'std::_Bit_iterator::reference'
102 | for(auto& el : is) el = false;
| ^~
Viruses.cpp:71:8: warning: unused variable 't' [-Wunused-variable]
71 | ll t = -1;
| ^