# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706168 | SamNguyen | Scales (IOI15_scales) | C++14 | 1 ms | 308 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 "scales.h"
#include <bits/stdc++.h>
using namespace std;
class DAG {
private:
int n;
vector<vector<int>> adj;
public:
DAG(int n): n(n) {
adj.assign(n + 1, vector<int>());
}
inline void add_edge(int u, int v) {
adj[u].push_back(v);
}
vector<int> unique_topo_order() {
vector<int> deg(n + 1, 0);
for (int u = 1; u <= n; u++) for (int v : adj[u])
deg[v]++;
queue<int> q;
for (int u = 1; u <= n; u++) if (deg[u] == 0)
q.push(u);
if (q.size() > 1)
return vector<int>();
vector<int> res;
while (not q.empty()) {
int u = q.front(); q.pop();
res.push_back(u);
if (int(res.size()) == n)
break;
vector<int> nxts;
for (int v : adj[u]) {
deg[v]--;
if (deg[v] == 0)
nxts.push_back(v);
}
if (nxts.size() > 1)
return vector<int>();
q.push(nxts.front());
}
return res;
}
};
mt19937 rnd(82394 + time(NULL));
void init(int T) {
}
void orderCoins() {
DAG dag(6);
vector<int> inds = {1, 2, 3, 4, 5, 6};
vector<int> topo;
while (true) {
topo = dag.unique_topo_order();
if (not topo.empty())
break;
shuffle(inds.begin(), inds.end(), rnd);
int A = inds[0], B = inds[1], C = inds[2];
int X = getLightest(A, B, C);
int Y = getMedian(A, B, C);
int Z = getHeaviest(A, B, C);
dag.add_edge(X, Y);
dag.add_edge(Y, Z);
}
int W[5];
copy(topo.begin(), topo.end(), W);
answer(W);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |