#include "simurgh.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
int m = u.size();
vii seen(m);
rep(i, m) {
if (!seen[i]) {
vii curr[3];
vii parent(n, -1);
function<int(int)> root;
root = [&](int x) {
if (parent[x] < 0) {
return x;
}
return parent[x] = root(parent[x]);
};
vii query;
rep(j, m) {
int ru = root(u[j]), rv = root(v[j]);
if (ru == rv) {
continue;
}
if ((root(u[i]) == ru && root(v[i]) == rv) || (root(u[i]) == rv && root(v[i]) == ru)) {
curr[seen[j]].emplace_back(j);
continue;
}
if (parent[ru] < parent[rv]) {
swap(ru, rv);
}
parent[rv] += parent[ru];
parent[ru] = rv;
query.emplace_back(j);
}
if (curr[0].size() == 1 && curr[1].empty() && curr[2].empty()) {
seen[curr[0][0]] = 2;
continue;
}
vii ans;
int amax = 0, amin = n;
forin(x, curr[0]) {
query.emplace_back(x);
ans.emplace_back(count_common_roads(query));
amax = max(amax, ans.back());
amin = min(amin, ans.back());
query.pop_back();
}
if (amin == amax) {
if (!curr[1].empty()) {
query.emplace_back(curr[1][0]);
amin = count_common_roads(query);
amax = amin + 1;
} else if (!curr[2].empty()) {
query.emplace_back(curr[2][0]);
amax = count_common_roads(query);
}
}
rep(j, curr[0].size()) {
if (ans[j] == amax) {
seen[curr[0][j]] = 2;
} else {
seen[curr[0][j]] = 1;
}
}
}
}
vii res;
rep(i, m) {
if (seen[i] == 2) {
res.emplace_back(i);
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
204 KB |
correct |
4 |
Correct |
1 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
1 ms |
204 KB |
correct |
7 |
Correct |
0 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
204 KB |
correct |
4 |
Correct |
1 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
1 ms |
204 KB |
correct |
7 |
Correct |
0 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
4 ms |
204 KB |
correct |
15 |
Correct |
4 ms |
204 KB |
correct |
16 |
Correct |
4 ms |
204 KB |
correct |
17 |
Correct |
3 ms |
204 KB |
correct |
18 |
Correct |
2 ms |
204 KB |
correct |
19 |
Correct |
4 ms |
204 KB |
correct |
20 |
Correct |
4 ms |
312 KB |
correct |
21 |
Correct |
3 ms |
204 KB |
correct |
22 |
Correct |
3 ms |
204 KB |
correct |
23 |
Correct |
3 ms |
204 KB |
correct |
24 |
Correct |
2 ms |
204 KB |
correct |
25 |
Correct |
1 ms |
204 KB |
correct |
26 |
Correct |
2 ms |
204 KB |
correct |
27 |
Correct |
2 ms |
204 KB |
correct |
28 |
Correct |
1 ms |
204 KB |
correct |
29 |
Correct |
1 ms |
204 KB |
correct |
30 |
Correct |
2 ms |
204 KB |
correct |
31 |
Correct |
3 ms |
204 KB |
correct |
32 |
Correct |
3 ms |
204 KB |
correct |
33 |
Correct |
3 ms |
204 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
204 KB |
correct |
4 |
Correct |
1 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
1 ms |
204 KB |
correct |
7 |
Correct |
0 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
4 ms |
204 KB |
correct |
15 |
Correct |
4 ms |
204 KB |
correct |
16 |
Correct |
4 ms |
204 KB |
correct |
17 |
Correct |
3 ms |
204 KB |
correct |
18 |
Correct |
2 ms |
204 KB |
correct |
19 |
Correct |
4 ms |
204 KB |
correct |
20 |
Correct |
4 ms |
312 KB |
correct |
21 |
Correct |
3 ms |
204 KB |
correct |
22 |
Correct |
3 ms |
204 KB |
correct |
23 |
Correct |
3 ms |
204 KB |
correct |
24 |
Correct |
2 ms |
204 KB |
correct |
25 |
Correct |
1 ms |
204 KB |
correct |
26 |
Correct |
2 ms |
204 KB |
correct |
27 |
Correct |
2 ms |
204 KB |
correct |
28 |
Correct |
1 ms |
204 KB |
correct |
29 |
Correct |
1 ms |
204 KB |
correct |
30 |
Correct |
2 ms |
204 KB |
correct |
31 |
Correct |
3 ms |
204 KB |
correct |
32 |
Correct |
3 ms |
204 KB |
correct |
33 |
Correct |
3 ms |
204 KB |
correct |
34 |
Correct |
350 ms |
964 KB |
correct |
35 |
Correct |
380 ms |
1144 KB |
correct |
36 |
Correct |
247 ms |
916 KB |
correct |
37 |
Correct |
24 ms |
336 KB |
correct |
38 |
Correct |
392 ms |
1164 KB |
correct |
39 |
Correct |
302 ms |
992 KB |
correct |
40 |
Correct |
237 ms |
996 KB |
correct |
41 |
Correct |
363 ms |
1272 KB |
correct |
42 |
Correct |
364 ms |
1092 KB |
correct |
43 |
Correct |
181 ms |
716 KB |
correct |
44 |
Correct |
149 ms |
648 KB |
correct |
45 |
Correct |
189 ms |
828 KB |
correct |
46 |
Correct |
131 ms |
584 KB |
correct |
47 |
Correct |
57 ms |
332 KB |
correct |
48 |
Correct |
9 ms |
308 KB |
correct |
49 |
Correct |
19 ms |
332 KB |
correct |
50 |
Correct |
59 ms |
332 KB |
correct |
51 |
Correct |
178 ms |
708 KB |
correct |
52 |
Correct |
153 ms |
640 KB |
correct |
53 |
Correct |
130 ms |
588 KB |
correct |
54 |
Correct |
180 ms |
756 KB |
correct |
55 |
Correct |
210 ms |
716 KB |
correct |
56 |
Correct |
172 ms |
836 KB |
correct |
57 |
Correct |
171 ms |
716 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Incorrect |
147 ms |
1928 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
correct |
2 |
Correct |
1 ms |
204 KB |
correct |
3 |
Correct |
1 ms |
204 KB |
correct |
4 |
Correct |
1 ms |
204 KB |
correct |
5 |
Correct |
1 ms |
204 KB |
correct |
6 |
Correct |
1 ms |
204 KB |
correct |
7 |
Correct |
0 ms |
204 KB |
correct |
8 |
Correct |
1 ms |
204 KB |
correct |
9 |
Correct |
1 ms |
204 KB |
correct |
10 |
Correct |
1 ms |
204 KB |
correct |
11 |
Correct |
1 ms |
204 KB |
correct |
12 |
Correct |
1 ms |
204 KB |
correct |
13 |
Correct |
1 ms |
204 KB |
correct |
14 |
Correct |
4 ms |
204 KB |
correct |
15 |
Correct |
4 ms |
204 KB |
correct |
16 |
Correct |
4 ms |
204 KB |
correct |
17 |
Correct |
3 ms |
204 KB |
correct |
18 |
Correct |
2 ms |
204 KB |
correct |
19 |
Correct |
4 ms |
204 KB |
correct |
20 |
Correct |
4 ms |
312 KB |
correct |
21 |
Correct |
3 ms |
204 KB |
correct |
22 |
Correct |
3 ms |
204 KB |
correct |
23 |
Correct |
3 ms |
204 KB |
correct |
24 |
Correct |
2 ms |
204 KB |
correct |
25 |
Correct |
1 ms |
204 KB |
correct |
26 |
Correct |
2 ms |
204 KB |
correct |
27 |
Correct |
2 ms |
204 KB |
correct |
28 |
Correct |
1 ms |
204 KB |
correct |
29 |
Correct |
1 ms |
204 KB |
correct |
30 |
Correct |
2 ms |
204 KB |
correct |
31 |
Correct |
3 ms |
204 KB |
correct |
32 |
Correct |
3 ms |
204 KB |
correct |
33 |
Correct |
3 ms |
204 KB |
correct |
34 |
Correct |
350 ms |
964 KB |
correct |
35 |
Correct |
380 ms |
1144 KB |
correct |
36 |
Correct |
247 ms |
916 KB |
correct |
37 |
Correct |
24 ms |
336 KB |
correct |
38 |
Correct |
392 ms |
1164 KB |
correct |
39 |
Correct |
302 ms |
992 KB |
correct |
40 |
Correct |
237 ms |
996 KB |
correct |
41 |
Correct |
363 ms |
1272 KB |
correct |
42 |
Correct |
364 ms |
1092 KB |
correct |
43 |
Correct |
181 ms |
716 KB |
correct |
44 |
Correct |
149 ms |
648 KB |
correct |
45 |
Correct |
189 ms |
828 KB |
correct |
46 |
Correct |
131 ms |
584 KB |
correct |
47 |
Correct |
57 ms |
332 KB |
correct |
48 |
Correct |
9 ms |
308 KB |
correct |
49 |
Correct |
19 ms |
332 KB |
correct |
50 |
Correct |
59 ms |
332 KB |
correct |
51 |
Correct |
178 ms |
708 KB |
correct |
52 |
Correct |
153 ms |
640 KB |
correct |
53 |
Correct |
130 ms |
588 KB |
correct |
54 |
Correct |
180 ms |
756 KB |
correct |
55 |
Correct |
210 ms |
716 KB |
correct |
56 |
Correct |
172 ms |
836 KB |
correct |
57 |
Correct |
171 ms |
716 KB |
correct |
58 |
Correct |
1 ms |
204 KB |
correct |
59 |
Correct |
1 ms |
204 KB |
correct |
60 |
Incorrect |
147 ms |
1928 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |