# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
838792 | ErJ | Keys (IOI21_keys) | C++17 | 3048 ms | 30968 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 <vector>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
vector<vector<pair<int, int>>> edges; //kam, key
vector<int> p, r;
vector<vector<int>> kv;//potrebuji klic na hranu vedouci do vrcholu
vector<bool> was;
int DFS(int u) {
int ans = 0;
queue<int> q;
q.push(u);
was[u] = true;
kv[r[u]][0] = -2;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int i = 0; i < edges[v].size(); i++) {
//cout << i << endl;
int w = edges[v][i].first;
int kw = edges[v][i].second;
if (kv[kw][0] == -2) {
if (!was[w]) {
was[w] = true;
q.push(w);
ans++;
if (kv[r[w]][0] != -2) {
kv[r[w]][0] = -2;
for (int i = 1; i < kv[r[w]].size(); i++) {
int x = kv[r[w]][i];
if (!was[x]) {
was[x] = true;
q.push(x);
ans++;
}
}
}
}
}
else {
if(!was[w]) kv[kw].push_back(w);
}
}
}
return ans;
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
int n = r.size();
int m = u.size();
edges.resize(n);
for (int i = 0; i < m; i++) {
edges[u[i]].push_back({ v[i], c[i] });
edges[v[i]].push_back({ u[i], c[i] });
}
p.resize(n);
::r = r;
int MIN = 1000000009;
//cout << "ahoj" << endl;
for (int i = 0; i < n; i++) {
//cout << "ahoj" << i << endl;
kv.clear();
was.clear();
kv.resize(n);
was.resize(n);
for (int j = 0; j < n; j++) {
kv[j].push_back(-1);
was[j] = false;
}
p[i] = DFS(i);
MIN = min(MIN, p[i]);
}
//cout << "ahojda" << endl;
vector<int> ans(n);
for (int i = 0; i < n; i++) {
//cout << p[i] << endl;
if (p[i] == MIN) {
ans[i] = 1;
}
else {
ans[i] = 0;
}
}
return ans;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |