Submission #510085

#TimeUsernameProblemLanguageResultExecution timeMemory
510085racsosabeAlkemija (COCI18_alkemija)C++14
80 / 80
75 ms11108 KiB
#include<bits/stdc++.h>
using namespace::std;

const int N = 100000 + 5;

int n;
int m;
int k;
int cnt[N];
bool vis[N];
vector<int> in[N];
vector<int> product[N];

int main(){
	scanf("%d %d", &n, &m);
	queue<int> Q;
	for(int i = 1; i <= m; i++){
		int x;
		scanf("%d", &x);
		Q.emplace(x);
		vis[x] = true;
	}
	scanf("%d", &k);
	for(int i = 1; i <= k; i++){
		int l, r;
		scanf("%d %d", &l, &r);
		cnt[i] = l;
		for(int j = 1; j <= l; j++){
			int x;
			scanf("%d", &x);
			in[x].emplace_back(i);
		}
		for(int j = 1; j <= r; j++){
			int x;
			scanf("%d", &x);
			product[i].emplace_back(x);
		}
	}
	while(!Q.empty()){
		int u = Q.front(); Q.pop();
		for(auto x : in[u]){
			cnt[x]--;
			if(cnt[x] == 0){
				for(auto y : product[x]){
					if(vis[y]) continue;
					Q.emplace(y);
					vis[y] = true;
				}
			}
		}
	}
	vector<int> res;
	for(int i = 1; i <= n; i++) if(vis[i]) res.emplace_back(i);
	printf("%d\n", (int)res.size());
	for(auto x : res) printf("%d%c", x, " \n"[x == res.back()]);
	return 0;
}

Compilation message (stderr)

alkemija.cpp: In function 'int main()':
alkemija.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
alkemija.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
alkemija.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
alkemija.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%d %d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~
alkemija.cpp:30:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
alkemija.cpp:35:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...