# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
137366 |
2019-07-27T14:14:50 Z |
fredbr |
Simurgh (IOI17_simurgh) |
C++17 |
|
2 ms |
256 KB |
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
struct Dsu {
vector<int> pai, w;
int comp;
Dsu(int n) : pai(n), w(n, 1), comp(n) {
iota(pai.begin(), pai.end(), 0);
}
int find(int x) {
if (x == pai[x]) return x;
return pai[x] = find(pai[x]);
}
void join(int x, int y) {
x = find(x), y = find(y);
if (w[x] < w[y]) swap(x, y);
pai[y] = x;
w[x] += w[y];
comp--;
}
bool con(int x, int y) {
return find(x) == find(y);
}
};
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
int m = u.size();
vector<int> golden(m);
for (int vtx = 0; vtx < n; vtx++) {
vector<pair<int, int>> num;
vector<int> r;
Dsu dsu(n);
for (int i = 0; i < m; i++) {
if (u[i] == vtx or v[i] == vtx) continue;
if (!dsu.con(u[i], v[i])) {
dsu.join(u[i], v[i]);
r.push_back(i);
}
}
for (int i = 0; i < m; i++) {
if (u[i] == vtx or v[i] == vtx) {
if (golden[i] == 0 and !dsu.con(u[i], v[i]) and dsu.comp == 2) {
r.push_back(i);
// int cnt = 35000;
num.push_back({i, count_common_roads(r)});
r.pop_back();
}
}
}
int maxi = 0;
for (auto const& p : num) {
maxi = max(maxi, p.second);
}
for (auto const& p : num) {
if (p.second == maxi) {
golden[p.first] = 1;
}
else {
golden[p.first] = -1;
}
}
}
vector<int> r;
Dsu dsu(n);
for (int i = 0; i < m; i++) {
if (golden[i] == 1) {
r.push_back(i);
dsu.join(u[i], v[i]);
}
}
for (int i = 0; i < m; i++) {
if (golden[i] != 1 and !dsu.con(u[i], v[i])) {
golden[i] = 1;
dsu.join(u[i], v[i]);
r.push_back(i);
}
}
return r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
correct |
2 |
Incorrect |
2 ms |
128 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |