#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n;
map <string, int> m;
int greska, bio[maxn];
vector <int> parent[maxn], v;
int ostavi[maxn], pocetak[maxn];
void dfs (int x, int poc){
if (bio[x] != -1 and x == poc){
ostavi[x] = 1;
return;
}
else if (bio[x] != -1){
if (pocetak[x] == 0) greska = 1;
else{
ostavi[bio[x]] = 1;
bio[x] = poc;
}
return;
}
bio[x] = poc;
if (x == poc) pocetak[x] = 1;
for (int i = 0; i < parent[x].size(); i++){
int y = parent[x][i];
dfs(y, poc);
}
}
int main (void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
int br = 1;
for (int i = 0; i < n; i++){
for (int j = 0; j <= br; j++) bio[j] = -1, ostavi[j] = 0, pocetak[j] = 0;
v.clear();
greska = 0;
string novi, s;
cin >> novi;
if (m[novi] != 0){
greska = 1;
}
cin >> s;
string roditelj;
cin >> roditelj;
while (roditelj != ";"){
v.push_back(m[roditelj]);
if (m[roditelj] == 0){
greska = 1;
}
else{
dfs(m[roditelj], m[roditelj]);
}
cin >> roditelj;
}
//cout << bio[1] << " " << bio[2] << " " << bio[3] << endl;
//cout << greska << endl;
if (greska == 1) cout << "greska" << endl;
else{
cout << "ok" << "\n";
m[novi] = br;
//cout << br << " : ";
for (int j = 0; j < v.size(); j++){
if (ostavi[v[j]] == 0){
//cout << v[j] << " ";
parent[br].push_back(v[j]);
}
}
br++;
//cout << endl;
}
}
return 0;
}
| # | 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... |