Submission #990625

#TimeUsernameProblemLanguageResultExecution timeMemory
990625alexddDijamant (COI16_dijament)C++17
100 / 100
65 ms644 KiB
#include<bits/stdc++.h> using namespace std; int n; unordered_map<string,int> id; bool cmp(int x, int y) { return x>y; } bool visited[1005]; int cnt[1005]; vector<int> con[1005]; void dfs(int nod) { visited[nod]=1; for(auto x:con[nod]) if(!visited[x]) dfs(x); } vector<int> nodes; signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { string nume,aux; cin>>nume>>aux; bool rau=0; if(id[nume]) rau=1; vector<int> v; while(cin>>aux) { if(aux==";") break; if(id[nume]) continue; if(!id[aux] || aux==nume) rau=1; v.push_back(id[aux]); } if(rau) { cout<<"greska\n"; continue; } for(int j=1;j<=n;j++) { visited[j]=0; cnt[j]=0; } sort(v.begin(),v.end(),cmp); for(auto x:v) { if(!visited[x]) { dfs(x); con[i].push_back(x); } } for(auto x:nodes) if(visited[x]) for(auto y:con[x]) cnt[y]++; for(auto x:nodes) { if(cnt[x]>=2) { rau=1; break; } } if(rau) { cout<<"greska\n"; continue; } nodes.push_back(i); id[nume]=i; cout<<"ok\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...