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

Dijamant

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

의견: 0

설명

We are observing class declarations in an obje\(ct-or\)iented programming language similar to C++. Each
class declaration is of the form “\(K\) : \(P\)1 \(P\)2 . . . \(Pk\) ;” where \(K\) is the name of the new class being
declared, and \(P\)1, P2, . . . , P\(k\) the names of classes being inherited by class \(K\). For example, “shape :
;” is a declaration of class “shape” that does not inherit any other class, whereas “square : shape
rectangle ;” is a declaration of class “square” that inherits classes “shape” and “rectangle”.
If class \(K\)1 inherits class \(K\)2, class \(K\)2 inherits class \(K\)3, and so on, up to class \(Km - 1\) that inherits class \(Km\),
then we say that all classes \(K_{1}\), K_{2}, . . . , K_{m}{−} are derived from class \(K_{m}\). The rules of the programming
language forbid circular definitions, so it is not allowed to have a class derived from itself. In other words,
the class hierarchy forms a directed acyclic graph. Additionally, it is not allowed for a \(so-ca\)lled diamond
to appear in the class hierarchy. A diamond consists of four different classes A, B, X, Y such that it holds:
• Classes \(X\) and \(Y\) are derived from \(A\).
• Class \(B\) is derived from both \(X\) and \(Y\) .
• Neither is class \(X\) derived from \(Y\) , nor is class \(Y\) derived from \(X\).
A
X
Y
B
Figure 1: A diamond
shape
circle
square
rectangle
runnable
thread
object
Figure 2: The hierarchy after processing all declarations from
the first sample test
You are given a series of class declarations to be processed sequentially, and determine for each one
whether it is correctly declared. The correctly declared classes are added to the hierarchy, while the
incorrect ones are discarded. Declaration “\(K\) : \(P\)1 \(P\)2 . . . \(Pk\) ;” is correctly declared if the following holds:
1. Class \(K\) hasn’t been declared yet.
2. All classes \(P\)1, P2, . . . , P\(k\) have been previously declared. Notice that this condition ensures that a
class can never be derived from itself, or that cycles cannot exist in the class hierarchy.
3. By adding class \(K\) that inherits \(P\)1, P2, . . . , P\(k\) the class hierarchy remains in order, that is, not a
single diamond is formed.
Write a programme that will process the declarations respectively as described above and determine the
correctness of each one of them.

제약

Subtask
Score
Limitations
1
13
\(1 \le n \le 100\), the correctness can be determined by considering only condition 1.
2
14
\(1 \le n \le 100\), the correctness can be determined by considering only conditions 1 and 2.
3
29
\(1 \le n \le 100\).
4
44
\(101 \le n \le 1\,000\).

입력 형식

The first line of input contains the integer \(n\) – the number of declarations. Each of the following \(n\) lines
contains a single declaration in the form of “\(K\) : \(P\)1 \(P\)2 . . . \(Pk\) ;” where \(P\)1, P2, . . . , P\(k\) is a series of zero,
one or more classes that class \(K\) inherits. All class names in a single declaration K, P1, P2, . . . , P\(k\) are
mutually different. Each class name is a string of at most 10 lower case letters of the English alphabet.
All the elements of a declaration (the class names and characters “:” and “;”) are separated by exactly
one space. In each specific declaration, for the number of classes \(k\) it holds \(0 \le k \le 1\,000\).
1 od 8

출력 형식

You must output \(n\) lines. The \(i^{th}\) line must contain “ok” if the \(i^{th}\) declaration is correct, and “greska” if
it isn’t.

예제 1
입력
10
shape : ;
rectangle : shape ;
circle : shape ;
circle : ;
square : shape rectangle ;
runnable : object ;
object : ;
runnable : object shape ;
thread : runnable ;
applet : square thread ;
출력
ok
ok
ok
greska
ok
greska
ok
ok
ok
greska
예제 2
입력
9
a : ;
x : ;
b : a x ;
c : b ;
d : a b c ;
e : d a ;
f : c e ;
y : x ;
g : c y e ;
출력
ok
ok
ok
ok
ok
ok
ok
ok
greska
문제 정보

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

출처 COCI 2015/2016 Olympiad

평가 및 의견

Dijamant

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

Log in to rate problems.

개별 의견

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

풀이 제출

Dijamant

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