This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define LL long long
#define Rep(i,x,y) for(int i = (x), stOxrj = (y); i <= stOxrj; ++i)
#define Irep(i,x,y) for(int i = (x), stOxrj = (y); i >= stOxrj; --i)
#define il inline
#define let const auto
#define ci const int&
#define VEC vector<int>
#define pb emplace_back
#define MP make_pair
#define PA pair<int, int>
#define fi first
#define se second
#define IT iterator
using namespace std;
il int read(){
int res = 0, flag = 1; char c = getchar();
while( c < '0' || c > '9' ){ if( c == '-' ) flag = -1; c = getchar(); }
while( c >= '0' && c <= '9' ) res = res * 10 + c - '0', c = getchar();
return res * flag;
}
const int N = 1005, E = N * N;
struct edge{ int nxt, to; }e[E];
int fir[N], cnt, tot;
void add(int u, int v){ e[++tot] = (edge){fir[u], v}; fir[u] = tot; }
map<string, int> mp;
int a[N]; bool vs[N];
void Solve(){
bool gg = 0;
string tmp, cur; cin>>cur;
if(mp.count(cur)) gg = 1;
int l = 0;
cin>>tmp;
while(1){
cin>>tmp;
if(!strcmp(tmp.c_str(), ";")) break;
if(!gg){
if(!mp.count(tmp)) gg = 1;
else a[++l] = mp[tmp];
}
}
sort(a + 1, a + l + 1, [&](ci A, ci B){ return A > B; } );
memset(vs, 0, sizeof(vs));
Rep(i, 1, l) if(!gg){
int u = a[i];
if(vs[u]) { a[i] = 0; continue; }
for(int j = fir[u]; j; j = e[j].nxt){
int v = e[j].to;
if(vs[v]) gg = 1;
vs[v] = 1;
}
}
if(gg) { puts("greska"); return ; }
puts("ok");
mp[cur] = ++cnt;
Rep(i, 1, cnt - 1) if(vs[i]) add(cnt, i);
Rep(i, 1, l) if(a[i]) add(cnt, a[i]);
}
signed main(){
int n; cin>>n;
while(n--) Solve();
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... |