Submission #299982

# Submission time Handle Problem Language Result Execution time Memory
299982 2020-09-16T04:43:30 Z shrek12357 Alkemija (COCI18_alkemija) C++14
80 / 80
667 ms 50040 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	//vector<int> nums;
	queue<int> q;
	bool vis[100005];
	for (int i = 0; i <= n; i++) {
		vis[i] = false;
	}
	for (int i = 0; i < m; i++) {
		int temp;
		cin >> temp;
		q.push(temp);
		vis[temp] = true;
	}
	map<set<int>, vector<set<int>>> adjList;
	map<int, vector<set<int>>> groups;
	map<set<int>, int> counts;

	int k;
	cin >> k;
	for (int i = 0; i < k; i++) {
		int a, b;
		cin >> a >> b;
		set<int> s1, s2;
		for (int j = 0; j < a; j++) {
			int temp;
			cin >> temp;
			s1.insert(temp);
		}
		for (int j = 0; j < b; j++) {
			int temp;
			cin >> temp;
			s2.insert(temp);
		}
		adjList[s1].push_back(s2);
		for (auto i : s1) {
			groups[i].push_back(s1);
		}
		counts[s1] = 0;
	}
	int counter = 0;
	while (q.size() > 0) {
		//vis[q.front()] = true;
		counter++;
		int curNode = q.front();
		q.pop();
		for (auto i : groups[curNode]) {
			counts[i]++;
			if (counts[i] == i.size()) {
				for (auto j : adjList[i]) {
					for (auto k : j) {
						if (!vis[k]) {
							vis[k] = true;
							q.push(k);
						}
					}
				}
			}
		}
	}
	cout << counter << endl;
	int cnt = 0;
	for (int i = 0; i <= n; i++) {
		if (vis[i]) {
			cnt++;
			cout << i;
			if (cnt != counter) {
				cout << " ";
			}
		}
	}
	cout << endl;
}

Compilation message

alkemija.cpp: In function 'int main()':
alkemija.cpp:62:18: warning: comparison of integer expressions of different signedness: 'std::map<std::set<int>, int>::mapped_type' {aka 'int'} and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |    if (counts[i] == i.size()) {
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 15992 KB Output is correct
2 Correct 222 ms 19576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 35216 KB Output is correct
2 Correct 502 ms 38904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 667 ms 48248 KB Output is correct
2 Correct 489 ms 40568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 667 ms 50040 KB Output is correct
2 Correct 648 ms 48632 KB Output is correct