Submission #86059

# Submission time Handle Problem Language Result Execution time Memory
86059 2018-11-24T11:12:38 Z kraljlavova1 Alkemija (COCI18_alkemija) C++11
80 / 80
197 ms 16024 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const int MAX=100010;
int n,m;
int x,sz;
int k;
int R[MAX],P[MAX];
vector<int>r[MAX],p[MAX];
int bio[MAX],cnt[MAX];
vector<int>st;
vector<int>lst[MAX];
void solve(){
	while(!st.empty()){
		int x=st.back();
		st.pop_back();
		if(bio[x]) continue;
		bio[x]=1;
		for(int idx:lst[x]){
			cnt[idx]--;
			if(!cnt[idx]){
				for(int j=0;j<P[idx];j++){
					st.push_back(p[idx][j]);
				}
			}
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>x;
		st.push_back(x);
	}
	cin>>k;
	for(int i=0;i<k;i++){
		cin>>R[i]>>P[i];cnt[i]=R[i];
		for(int j=0;j<R[i];j++){
			cin>>x;
			r[i].push_back(x);
			lst[x].push_back(i);
		}
		for(int j=0;j<P[i];j++){
			cin>>x;
			p[i].push_back(x);
		}
	}
	solve();
	for(int i=1;i<=n;i++){
		if(bio[i]) sz++;
	}
	cout<<sz<<"\n";
	for(int i=1;i<=n;i++){
		if(bio[i]) cout<<i<<" ";
	}cout<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 9348 KB Output is correct
2 Correct 84 ms 10528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 12324 KB Output is correct
2 Correct 134 ms 14072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 15232 KB Output is correct
2 Correct 180 ms 15232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 16024 KB Output is correct
2 Correct 165 ms 16024 KB Output is correct