# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
838791 | ErJ | Keys (IOI21_keys) | C++17 | 0 ms | 0 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;
}