# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299982 | shrek12357 | Alkemija (COCI18_alkemija) | C++14 | 667 ms | 50040 KiB |
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 <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 (stderr)
# | 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... |