이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include "simurgh.h"
using namespace std;
using ll = long long;
#define pb push_back
#define sz(v) ((int)v.size())
int p[500];
int getp(int x) { return p[x] = (x == p[x] ? x : getp(p[x])); }
int uni(int a, int b) {
a = getp(a);
b = getp(b);
if (a == b) return 0;
p[a] = b;
return 1;
}
vector<int>
find_roads(int n, vector<int> u, vector<int> v) {
int m = sz(u);
vector<int> ans, r, us(m, 0), z;
for (int i = 0; i < n-1; ++i) {
for (int i = 0; i < n; ++i) p[i] = i;
int c = 0;
if (sz(ans) == n-1) break;
r = ans;
for (auto x : ans) {
c += uni(u[x], v[x]);
}
int p = 0;
while (c < n-2) {
if (uni(u[p], v[p])) {
++c;
r.pb(p);
}
++p;
}
while (us[p] || getp(u[p]) == getp(v[p]))
++p;
r.pb(p);
z.clear();
z.pb(p);
assert(sz(r) == n-1);
int x = count_common_roads(r);
for (int j = p+1; j < m; ++j) {
if(us[j]) continue;
if (getp(u[j]) == getp(v[j])) continue;
r[n-2] = j;
us[j] = 1;
int l = count_common_roads(r);
if (l == x) {
z.pb(j);
} else if (l < x) {
break;
} else if (l > x) {
z.clear(); z.pb(j);
break;
}
}
for (auto j : z)
ans.pb(j);
}
return ans;
}
# | 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... |