이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//COI dijament
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int, int> ii;
const int maxn = 1e3+10, inf = 0x3f3f3f3f;
struct node
{
int u, f, d;
};
int n, nd;
map<string, int> inh;
int t, pross[maxn], vis[maxn];
vector<int> graph[maxn];
int dfs(int u)
{
vis[u] = 1;
pross[u] = 1;
for(int v: graph[u])
{
if(!vis[v])
{
if(dfs(v) == 0) return 0;
}
else if(pross[v] == 1) return 0;
}
pross[u] = 0;
return 1;
}
void init()
{
memset(pross, 0, sizeof pross);
memset(vis, 0, sizeof vis);
}
void debug()
{
for(int i = 1 ; i <= nd ; ++i)
{
if(graph[i].size() > 0) cout << i << ": \n ";
for(int u: graph[i]){
cout << u << ' ';
}
if(graph[i].size() > 0) cout << "\n\n";
}
}
int main()
{
cin >> n;
for(int i = 0 ; i < n ; ++i)
{
string name, pt, s;
cin >> name >> pt;
int ok = 1;
if(inh[name] != 0) ok = 0;
vector<int> ad;
while(cin >> s && s != ";")
{
if(inh[s] == 0 || s == name) ok = 0;
else ad.push_back(inh[s]);
}
if(!ok) cout << "greska\n";
else
{
inh[name] = ++nd;
for(auto v: ad)
{
graph[nd].push_back(v);
// g[v].push_back(nd);
}
init();
ok = min(ok, dfs(nd));
//cout << "loop: " << i << " ok: " << ok << "\n";
//debug();
if(!ok)
{
//cout << "1: ";
//for(auto x: graph[nd]) g[x].pop_back();
graph[nd].clear();
inh[name] = 0;
nd--;
cout << "greska\n";
continue;
}
/*ok = diamond(nd);
if(!ok)
{
//cout << "2: ";
graph[nd].clear();
inh[name] = 0;
nd--;
cout << "greska\n";
continue;
}*/
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... |