RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00479

Alkemija

Unrated 레이팅 미적용
난이도
1s
시간 제한
64MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

1 \(s / 64\) \(MB / 80\) points

In ancient times, when alchemists were searching for gold, the world was familiar with a total

of \(N\) distinct substances, denoted with 1 to \(N\) . During many years of hard work, searching for

the secret formula, alchemists discovered a series of interesting regularities - alchemical

reactions . In one reaction, it’s possible to transform substance set { \(X\) {1}{ }, \(X\) {2}{ }, ..., \(X\) {L}{ }} to another

substance set { \(Y\) {1}{ }, \(Y\) {2}{ }, ..., \(Y\) {R}{ }}. For example, the substance set {1, 4, 5} might react once and

create the new substance set {2, 6}.

Joško is a modern alchemist and has \(M\) distinct substances denoted with \(A\) {1}{ }, \(A\) {2}{ }, ..., \(A\) {M}{ }. He

has an unlimited quantity of each substance from that set. Joško wants to know which

substances he can create using a list of reactions of ancient alchemists, so he’s asking you

to help him solve this problem.

제약

In test cases worth 60% of total points, it will hold:

\(N\) , \(K\) ≤ 500.

The sum of all \(L\) values and the sum of all \(R\) values won’t exceed 500.

1 \(s / 64\) \(MB / 80\) points

입력 형식

The first line of input contains two integers \(N\) and \(M\) (1 ≤ \(M\)\(N \le 100\,000\)), the numbers

from the task.
The second line of input contains \(M\) integers \(A\) {i} (1 ≤ \(A\) \(N\) ), labels of the substances Joško

has in the beginning.
The third line of input contains the integer \(K\) (1 ≤ \(K \le 100\,000\)), the number of known

reactions.
The following 3· \(K\) lines contain a list of reactions. Each reaction is described with 3 lines in

the following way:

The first line contains the integers \(L\) and \(R\) (1 ≤ \(L\) , \(R\)\(N\) ).

The second line contains \(L\) distinct integers \(X\) {i}{ } (1 ≤ \(X\) {i}{ } ≤ \(N\) ).

The third line contains \(R\) distinct integers \(Y\) {i}{ } (1 ≤ \(Y\) {i}{ } ≤ \(N\) ).

This describes the reaction with which the substance set { \(X\) {1}{ }, \(X\) {2}{ }, ..., \(X\) {L}{ }} transforms

into substance set { \(Y\) {1}{ }, \(Y\) {2}{ }, ..., \(Y\) {R}{ }}.
The sum of all \(L\) values won’t exceed 100 000.
The sum of all \(R\) values won’t exceed 100 000.

출력 형식

The first line of output must contain the integer \(X\) , the number of obtainable substances.
The second line of output must contain \(X\) distinct integers \(B\) {i}{ }, sorted ascendingly, that

represent the labels of the obtainable substances.

예제 1
입력
4 2
1 2
2
2 1
1 2
3
2 1
1 3
4

6 3
1 4 5
3
3 2
2 3 4
1 6
1 3
4
1 5 6
1 1
6
2
출력
output
4
1 2 3 4

5
1 2 4 5 6
설명

Clarification of the first test case:
There are 2 reactions.
The first reaction transforms substance set {1, 2} into substance set {3}.
The second reaction transforms substance set {1, 3} into substance set {4}.
Joško initially has substances from the set {1, 2}.
Using the first reaction, Joško can obtain substance 3, after which he has substances from the set {1,

2, 3}.
After that, using the second reaction, he can also obtain substance 4.

Clarification of the second test case:
Joško initially has substances from the set {1, 4, 5}.
Using the second reaction, it is possible to obtain substance 6, after which it is possible to apply the

third reaction, giving substance 2.
The first reaction is impossible to apply because Joško doesn’t have substance 3.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2017/2018 Contest 6

평가 및 의견

Alkemija

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Alkemija

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8