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 pb push_back
#define mem(x, y) memset(& x, y, sizeof(x))
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cerr if(dbg)cerr
using namespace std;
const int n0=103;
int n;
string name[n0];
bitset<n0> gr[n0],ls[n0][n0];
map<string,int> ind;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
string line;
getline(cin,line);
for(int i=0; i<SZ(line); i++) {
if(line[i]>='0' && line[i]<='9') {
n=n*10+(line[i]-'0');
}
}
for(int i=0; i<n; i++) {
string cur;
line="";
getline(cin,line);
int pos=0;
for(int j=0; j<SZ(line); j++) {
if(line[j]==' ') {
pos=j+3;
break;
} else {
cur+=line[j];
}
}
int ok=1;
if(ind.find(cur)!=end(ind)) {
ok=0;
} else {
name[i]=cur;
ind[cur]=i;
cur="";
gr[i][i]=1;
for(int j=pos; j<SZ(line); j++) {
if(line[j]==';') break;
if(line[j]==' ') {
if(ind.find(cur)==end(ind)) {
ok=0;
break;
}
gr[i]|=gr[ind[cur]];
cur="";
} else {
cur+=line[j];
}
}
}
if(ok) {
int diamond=0;
for(int j=0; j<i; j++) {
if(!gr[i][j]) continue;
for(int k=0; k<i; k++) {
if(!gr[i][k]) continue;
if(!gr[j][k] && !gr[k][j]) {
if((ls[j][k]&ls[k][j]).count()) {
diamond=1;
}
}
}
}
if(diamond) {
gr[i].reset();
cout << "greska\n";
} else {
for(int j=0; j<i; j++) {
if(!gr[i][j]) {
for(int k=0; k<j; k++) {
if(gr[i][k]) {
ls[i][j][k]=1;
}
}
}
}
cout << "ok\n";
}
}
}
}
# | 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... |