# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
723955 | bane | Dijamant (COI16_dijament) | C++17 | 182 ms | 4628 KiB |
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 <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define fr first
#define sc second
#define pq priority_queue
#define all(x) begin(x), end(x)
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll inf = (ll)1e18;
const ll MOD = (ll)1e9 + 7;
const int MAXN = 2000;
void setPrec() { cout << fixed << setprecision(15); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
unsyncIO(); setPrec();
if ((int)s.size()) setIn(s+".in"), setOut(s+".out");
}
int par[MAXN];
void solve(){
int N; cin >> N;
map<string,int>vis;
vector<int>a[N + 1];
for (int i = 1; i <= N; i++){
string s;
cin >> s;
char c;
cin >> c;
vector<int> v;
bool bad = 0;
while(1){
string t;
cin >> t;
if(t == ";")break;
if(vis[t] == 0)bad = 1;
v.push_back(vis[t]);
}
if (vis[s])bad = 1;
// vis[k] = i;
if (bad){
cout<<"greska"<<'\n';
continue;
}
for (int j = 0; j<=N; j++)par[j] = 0;
function<void(int)>dfs = [&](int v){
for(auto u:a[v]){
if(bad)return;
if(par[u]){
if(par[u] != v)
bad = 1;
}
else{
par[u] = v;
dfs(u);
}
}
};
for (int p : v)dfs(p);
if (!bad){
vis[s] = i;
cout<<"ok"<<'\n';
for (auto p : v){
if (par[p] == 0){
//koren
a[i].pb(p);
}
}
}else{
cout<<"greska"<<'\n';
}
}
}
int main(){
setIO();
solve();
return 0;
}
Compilation message (stderr)
# | 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... |