Stop writing articles that don't rank.
Stop writing articles that don't rank. Midgen AI's Article Generator crafts well-researched, SEO-optimized content that engages readers and pleases search engines.
🔗 https://midgen.ai/
#SEOContent #ArticleWriting #ContentMarketing #midgen #midgenai #midgenhq #RankHigher
Comments
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
set st; // store chemicals
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
st.insert(x);
}
vector> rules(m);
for (int i = 0; i < m; i++) {
cin >> rules[i][0] >> rules[i][1] >> rules[i][2];
}
bool changed = true;
// repeat until no new chemical is added
while (changed) {
changed = false;
for (auto &r : rules) {
long long x = r[0], y = r[1], z = r[2];
if (st.count(x) && st.count(y) && !st.count(z)) {
st.insert(z);
changed = true; // new chemical added
}
}
}
cout << st.size() << "\n";
}
return 0;
}
Post a Comment