답안 #239831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
239831 2020-06-17T11:11:45 Z MrRobot_28 Alkemija (COCI18_alkemija) C++17
80 / 80
170 ms 12784 KB
#include <bits/stdc++.h>
                  
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	vector <vector <int> > num(n);
	vector <int> a(m);
	for(int i = 0; i < m; i++)
	{
		cin >> a[i];
		a[i]--;
	}
	int k;
	cin >> k;
	vector <int> cnt(k);
	vector <vector <int> > vec1(k), vec2(k);
	vector <bool> used(k);
	vector <bool> used1(n);
	for(int i = 0; i < k; i++)
	{
		int l, r;
		cin >> l >> r;
		vec1[i].resize(l);
		vec2[i].resize(r);
		cnt[i] = l;
		for(int j = 0; j < l; j++)
		{
			cin >> vec1[i][j];
			vec1[i][j]--;
			num[vec1[i][j]].push_back(i);
		}
		for(int j = 0; j < r; j++)
		{
			cin >> vec2[i][j];
			vec2[i][j]--;
		}
	}
	queue <int> q;
	for(int i = 0; i < m; i++)
	{
		used1[a[i]] = true;
		for(int j = 0; j < num[a[i]].size(); j++)
		{
			int ind = num[a[i]][j];
			cnt[ind]--;
			if(cnt[ind] == 0)
			{
				used[ind] = true;
				q.push(ind);
			}
		}
	}
	while(q.size() != 0)
	{
		int v = q.front();
		q.pop();
		for(int i = 0; i < vec2[v].size(); i++)
		{
			int to = vec2[v][i];
			if(!used1[to])
			{
				used1[to] = true;
				for(int j = 0; j < num[to].size(); j++)
				{
					int to1 = num[to][j];
					cnt[to1]--;
					if(cnt[to1] == 0)
					{
						used[to1] = true;
						q.push(to1);
					}
				}
			}
		}
	}
	vector <int> ans;
	for(int i = 0; i < n; i++)
	{
		if(used1[i])
		{
			ans.push_back(i);
		}
	}
	cout << ans.size() << "\n";
	for(int i = 0; i < ans.size(); i++)
	{
		cout << ans[i] + 1 << " ";
	}
	return 0;
}	

Compilation message

alkemija.cpp: In function 'int main()':
alkemija.cpp:43:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < num[a[i]].size(); j++)
                  ~~^~~~~~~~~~~~~~~~~~
alkemija.cpp:58:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vec2[v].size(); i++)
                  ~~^~~~~~~~~~~~~~~~
alkemija.cpp:64:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j < num[to].size(); j++)
                    ~~^~~~~~~~~~~~~~~~
alkemija.cpp:86:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ans.size(); i++)
                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 3576 KB Output is correct
2 Correct 59 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 7832 KB Output is correct
2 Correct 119 ms 9076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 11252 KB Output is correct
2 Correct 134 ms 9112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 170 ms 12784 KB Output is correct
2 Correct 151 ms 12148 KB Output is correct