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>
using namespace std;
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define debug(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define debug(...) "zzz"
#endif
using LL = long long;
using LD = long double;
using pii = pair<LL,LL>;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
template<typename T, typename = void> struct is_iterable : false_type {};
template<typename T> struct is_iterable<T, void_t<decltype(begin(declval<T>())),decltype(end(declval<T>()))>> : true_type {};
template<typename T> typename enable_if<is_iterable<T>::value&&!is_same<T, string>::value,ostream&>::type operator<<(ostream &cout, T const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename T> typename enable_if<is_iterable<T>::value&&!is_same<T, string>::value,ostream&>::type operator<<(ostream &cout, T const &v) {
cout << "[";
for (auto it = v.begin(); it != v.end();) {
cout << *it;
if (++it != v.end()) cout << ", ";
}
return cout << "]";
}
//var
LL T;
void solve() {
LL n, m;
cin >> n >> m;
set<LL> v;
while (m--) {
LL x; cin >> x;
x--;
v.insert(x);
}
LL k; cin >> k;
vector<pair<set<LL>, set<LL>>> a(k);
vector<vector<LL>> hit(n);
F0R (i, k) {
auto& [s1, s2] = a[i];
LL l, r;
cin >> l >> r;
while (l--) {
LL x; cin >> x; x--;
if (!v.count(x)) {
s1.insert(x);
hit[x].pb(i);
}
}
while (r--) {
LL x; cin >> x; x--;
s2.insert(x);
}
}
queue<LL> rmv;
F0R (i, k) {
if (a[i].f.empty()) {
rmv.push(i);
}
}
vector<LL> visitedSet(k);
while (!rmv.empty()) {
LL g = rmv.front();
rmv.pop();
if (visitedSet[g])
continue;
visitedSet[g] = true;
auto& [s1, s2] = a[g];
assert(s1.empty());
for (auto u : s2) if (!v.count(u)) {
v.insert(u);
for (auto z : hit[u]) {
if (a[z].f.count(u)) {
a[z].f.erase(u);
if (a[z].f.empty()) {
rmv.push(z);
}
}
}
}
s2.clear();
}
vector<LL> ans;
for (auto u : v)ans.pb(u);
cout << ans.size() << '\n';
F0R (i, (int)ans.size())
cout << ans[i] + 1 << " \n"[i == (int)ans.size() - 1];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
T = 1;
//cin >> T;
FOR(t, T)
solve();
cout.flush();
return 0;
}
# | 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... |
# | 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... |