# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
215938 | 2020-03-26T12:39:48 Z | SamAnd | Fire drill (LMIO18_sauga) | C++17 | 800 ms | 3084 KB |
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 1003; mt19937 rnd(3141); int tt, n, ss; vector<int> a[N]; int u[N]; vector<int> v; bool c[N]; void dfs(int x) { c[x] = true; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (!c[h]) dfs(h); } v.push_back(x); } int vu[N]; int ansq; vector<int> ans; int main() { scanf("%d%d%d", &tt, &n, &ss); for (int i = 1; i <= n; ++i) { int q; scanf("%d", &q); while (q--) { int x; scanf("%d", &x); a[i].push_back(x); } } for (int i = 1; i <= n; ++i) u[i] = i; while ((double)clock() / CLOCKS_PER_SEC < 0.8) { for (int i = n; i >= 1; --i) { swap(u[i], u[rnd() % n + 1]); } memset(c, false, sizeof c); v.clear(); for (int i = 1; i <= n; ++i) { int x = u[i]; if (!c[x]) dfs(x); } for (int i = 0; i < n; ++i) vu[v[i]] = i; int q = 0; for (int i = 0; i < n; ++i) { int x = v[i]; for (int j = 0; j < a[x].size(); ++j) { int h = a[x][j]; if (vu[h] > i) { ++q; break; } } } if (ans.empty() || q < ansq) { ans = v; ansq = q; } } for (int i = 0; i < n; ++i) printf("%d\n", ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 800 ms | 3084 KB | Output is correct |
2 | Partially correct | 800 ms | 504 KB | Output is partially correct |
3 | Partially correct | 800 ms | 504 KB | Output is partially correct |
4 | Partially correct | 800 ms | 504 KB | Output is partially correct |
5 | Partially correct | 800 ms | 504 KB | Output is partially correct |
6 | Partially correct | 800 ms | 504 KB | Output is partially correct |
7 | Partially correct | 800 ms | 888 KB | Output is partially correct |
8 | Partially correct | 800 ms | 2808 KB | Output is partially correct |
9 | Partially correct | 800 ms | 660 KB | Output is partially correct |
10 | Correct | 800 ms | 504 KB | Output is correct |