Submission #585802

#TimeUsernameProblemLanguageResultExecution timeMemory
585802FatihSolakDijamant (COI16_dijament)C++17
100 / 100
299 ms4624 KiB
#include <bits/stdc++.h> #define N 1005 using namespace std; int par[N]; vector<int> adj[N]; bool ok; void dfs(int v){ for(auto u:adj[v]){ if(!ok)return; if(par[u]){ if(par[u] != v) ok = 0; } else{ par[u] = v; dfs(u); } } } void solve(){ int n,q; n = 0; cin >> q; map<string,int> mp; while(q--){ string s; cin >> s; char c; cin >> c; vector<string> v; while(1){ string t; cin >> t; if(t == ";")break; v.push_back(t); } ok = 1; if(mp[s]){ ok = 0; } for(auto u:v){ if(!mp[u]){ ok = 0; } } for(int i = 1;i<n;i++){ par[i] = 0; } for(auto u:v){ dfs(mp[u]); } if(ok){ mp[s] = ++n; cout << "ok" << endl; for(auto u:v){ if(par[mp[u]] == 0){ adj[n].push_back(mp[u]); } } } else cout << "greska" << endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while(t--){ solve(); } #ifdef Local cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds."; #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...