#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
map<string, int> vis;
vector<bitset<1001>> anc(n + 1, 0);
int id = 1;
for (int i = 0; i < n; i++) {
string tmp;
getline(cin >> ws, tmp);
stringstream ss;
ss << tmp;
string s, K;
ss >> K;
if (vis[K]) {
cout << "greska" << '\n';
continue;
}
ss >> s;
vector<int> v;
int bl = 1;
while (1) {
ss >> s;
if (s == ";") {
break;
}
if (!vis[s]) {
bl = 0;
break;
}
v.push_back(vis[s]);
}
if (!bl) {
cout << "greska" << '\n';
continue;
}
int m = v.size();
for (int ii = 0; ii < m; ii++) {
for (int j = ii + 1; j < m; j++) {
if (anc[v[ii]][v[j]] || anc[v[j]][v[ii]]) {
continue;
}
for (int k = 0; k < 1001; k++) {
if (anc[v[ii]][k] && anc[v[j]][k]) {
bl = 0;
break;
}
}
if (!bl) {
break;
}
}
if (!bl) {
break;
}
}
if (!bl) {
cout << "greska" << '\n';
continue;
}
for (int ii = 0; ii < m; ii++) {
anc[id] |= anc[v[ii]];
anc[id][v[ii]] = 1;
}
vis[K] = id++;
cout << "ok" << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
463 ms |
504 KB |
Output is correct |
2 |
Correct |
530 ms |
716 KB |
Output is correct |
3 |
Correct |
18 ms |
4756 KB |
Output is correct |
4 |
Correct |
3 ms |
324 KB |
Output is correct |
5 |
Correct |
3 ms |
460 KB |
Output is correct |
6 |
Correct |
19 ms |
584 KB |
Output is correct |
7 |
Correct |
33 ms |
696 KB |
Output is correct |
8 |
Correct |
69 ms |
872 KB |
Output is correct |
9 |
Correct |
180 ms |
896 KB |
Output is correct |
10 |
Correct |
10 ms |
588 KB |
Output is correct |
11 |
Correct |
6 ms |
588 KB |
Output is correct |
12 |
Correct |
409 ms |
4168 KB |
Output is correct |