# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1110761 |
2024-11-10T11:39:55 Z |
Zero_OP |
Viruses (BOI20_viruses) |
C++14 |
|
1 ms |
336 KB |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define file(name) if(fopen(name".inp", "r")){ freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
template<typename T>
bool minimize(T& a, const T& b){
if(a > b){
return a = b, true;
}
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b){
return a = b, true;
}
return false;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vl = vector<ll>;
template<int ALPHABET = 26>
struct AhoCorasick{
static const int C = ALPHABET;
struct Node{
int link, next[C]; bool v;
Node(){
link = -1;
v = false;
memset(next, -1, sizeof(next));
}
};
vector<Node> Nodes;
AhoCorasick() : Nodes(){
Nodes.emplace_back();
}
int size(){ return sz(Nodes); }
int go(int u, int c){ return Nodes[u].next[c]; }
int link(int u){ return Nodes[u].link; }
void addString(const vector<int>& s){
int u = 0;
for(auto c : s){
if(Nodes[u].next[c] == -1){
Nodes[u].next[c] = size();
Nodes.emplace_back();
}
u = Nodes[u].next[c];
}
Nodes[u].v = true;
}
void build_links(){
queue<int> q;
q.push(0);
while(!q.empty()){
int u = q.front(), link = Nodes[u].link; q.pop();
if(u > 0) Nodes[u].v |= Nodes[link].v;
for(int c = 0; c < C; ++c){
int& nxt = Nodes[u].next[c], nxt_link = (u ? Nodes[link].next[c] : 0);
if(nxt == -1) nxt = nxt_link;
else{
Nodes[nxt].next[c] = nxt_link;
q.push(nxt);
}
}
}
}
bool check(int u){ return !Nodes[u].v; }
};
const ull inf = (1ULL << 63);
ull add(ull a, ull b){
if(a == inf || b == inf) return inf;
return a + b;
}
void upd(ull& a, ull b){
if(a == inf || b == inf) a = inf;
else a += b;
}
using item = pair<ull, int>; //for dijkstra
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int G, N, M;
cin >> G >> N >> M;
vector<int> from(N);
vector<vector<int>> mutations(N);
vector<vector<int>> options(G);
for(int i = 0; i < N; ++i){
int a, k;
cin >> a >> k;
from[i] = a;
for(int j = 0; j < k; ++j){
int b; cin >> b;
mutations[i].emplace_back(b);
options[b].emplace_back(i);
}
}
AhoCorasick<2> T;
for(int i = 0; i < M; ++i){
int l; cin >> l;
vector<int> s(l);
for(int& x : s) cin >> x;
T.addString(s);
}
if(M == 0){
vector<ull> dp(G, inf);
dp[0] = dp[1] = 1;
priority_queue<item, vector<item>, greater<item>> pq;
pq.push({1, 0}); pq.push({1, 1});
vector<bool> vis(G, false);
while(!pq.empty()){
ull cost; int u;
tie(cost, u) = pq.top(); pq.pop();
if(vis[u]) continue;
vis[u] = true;
for(auto id_mutation : options[u]){
int a = from[id_mutation];
ull res = 0;
for(auto x : mutations[id_mutation]){
upd(res, dp[x]);
}
if(minimize(dp[a], res)){
pq.push({dp[a], a});
}
}
}
for(int i = 2; i < G; ++i){
if(dp[i] == inf) cout << "Yes\n";
else cout << "No " << dp[i] << '\n';
}
}
return 0;
}
/*
Testcase
subtask 1 :
5 6 0
2 2 1 0
2 2 3 2
3 1 4
4 2 3 2
4 2 0 0
3 2 1 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |