#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
#include "simurgh.h"
typedef long long ll;
typedef long double ld;
using namespace std;
int n;
vector<int> u, v;
vector<int> p;
void clean() { p.assign(n, -1); for (int i = 0; i < n; i++) p[i] = i; }
int root(int i) { return p[i] == i ? i : p[i] = root(p[i]); }
bool merge(int k)
{
int i = u[k], j = v[k];
i = root(i), j = root(j);
if (i == j) return false;
p[i] = j;
return true;
}
int count_common_roads(const vector<int>& r);
vector<int> find_roads(int N, vector<int> U, vector<int> V)
{
n = N, u = U, v = V;
int m = u.size();
set<int> g, r;
for (int i = 0; i < m; i++) r.insert(i);
while (!r.empty())
{
clean();
vector<int> e;
for (int i : g) merge(i), e.push_back(i);
for (int i : r) if (merge(i)) e.push_back(i);
for (int i : e) r.erase(i);
if (r.empty())
{
sort(e.begin(), e.end());
return e;
}
e.push_back(*r.begin());
r.erase(r.begin());
vector<pair<int, int> > c; // pre tie na cykle - { pocet zlatych ciest, ktory sme dali prec }
for (int i : e) if (!g.count(i))
{
clean();
vector<int> e2;
for (int j : e) if (i != j)
{
if (!merge(j)) break;
e2.push_back(j);
}
if (e2.size() < n - 1) r.insert(i);
else c.push_back({ count_common_roads(e2), i });
}
int mx = max_element(c.begin(), c.end())->first;
for (pair<int, int> p : c) if (p.first == mx - 1)
{
g.insert(p.second);
}
}
return vector<int>(g.begin(), g.end());
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:67:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
67 | if (e2.size() < n - 1) r.insert(i);
| ~~~~~~~~~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
0 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
0 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
300 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
0 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
0 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
300 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
12 ms |
340 KB |
correct |
15 |
Correct |
14 ms |
392 KB |
correct |
16 |
Correct |
14 ms |
340 KB |
correct |
17 |
Correct |
7 ms |
340 KB |
correct |
18 |
Correct |
3 ms |
296 KB |
correct |
19 |
Correct |
8 ms |
340 KB |
correct |
20 |
Correct |
9 ms |
372 KB |
correct |
21 |
Correct |
8 ms |
368 KB |
correct |
22 |
Correct |
6 ms |
304 KB |
correct |
23 |
Correct |
5 ms |
296 KB |
correct |
24 |
Correct |
5 ms |
340 KB |
correct |
25 |
Correct |
2 ms |
280 KB |
correct |
26 |
Correct |
5 ms |
340 KB |
correct |
27 |
Correct |
5 ms |
340 KB |
correct |
28 |
Correct |
3 ms |
212 KB |
correct |
29 |
Correct |
2 ms |
212 KB |
correct |
30 |
Correct |
4 ms |
296 KB |
correct |
31 |
Correct |
5 ms |
296 KB |
correct |
32 |
Correct |
5 ms |
348 KB |
correct |
33 |
Correct |
4 ms |
300 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
0 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
0 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
300 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
12 ms |
340 KB |
correct |
15 |
Correct |
14 ms |
392 KB |
correct |
16 |
Correct |
14 ms |
340 KB |
correct |
17 |
Correct |
7 ms |
340 KB |
correct |
18 |
Correct |
3 ms |
296 KB |
correct |
19 |
Correct |
8 ms |
340 KB |
correct |
20 |
Correct |
9 ms |
372 KB |
correct |
21 |
Correct |
8 ms |
368 KB |
correct |
22 |
Correct |
6 ms |
304 KB |
correct |
23 |
Correct |
5 ms |
296 KB |
correct |
24 |
Correct |
5 ms |
340 KB |
correct |
25 |
Correct |
2 ms |
280 KB |
correct |
26 |
Correct |
5 ms |
340 KB |
correct |
27 |
Correct |
5 ms |
340 KB |
correct |
28 |
Correct |
3 ms |
212 KB |
correct |
29 |
Correct |
2 ms |
212 KB |
correct |
30 |
Correct |
4 ms |
296 KB |
correct |
31 |
Correct |
5 ms |
296 KB |
correct |
32 |
Correct |
5 ms |
348 KB |
correct |
33 |
Correct |
4 ms |
300 KB |
correct |
34 |
Correct |
2512 ms |
2512 KB |
correct |
35 |
Correct |
2021 ms |
2444 KB |
correct |
36 |
Correct |
1396 ms |
1764 KB |
correct |
37 |
Correct |
67 ms |
340 KB |
correct |
38 |
Correct |
1857 ms |
2492 KB |
correct |
39 |
Correct |
2049 ms |
2172 KB |
correct |
40 |
Correct |
1591 ms |
1752 KB |
correct |
41 |
Execution timed out |
3075 ms |
2516 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
1 ms |
212 KB |
correct |
3 |
Incorrect |
2287 ms |
6512 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
correct |
2 |
Correct |
0 ms |
212 KB |
correct |
3 |
Correct |
0 ms |
212 KB |
correct |
4 |
Correct |
0 ms |
212 KB |
correct |
5 |
Correct |
1 ms |
212 KB |
correct |
6 |
Correct |
0 ms |
212 KB |
correct |
7 |
Correct |
0 ms |
212 KB |
correct |
8 |
Correct |
0 ms |
212 KB |
correct |
9 |
Correct |
0 ms |
212 KB |
correct |
10 |
Correct |
0 ms |
212 KB |
correct |
11 |
Correct |
0 ms |
212 KB |
correct |
12 |
Correct |
0 ms |
300 KB |
correct |
13 |
Correct |
1 ms |
212 KB |
correct |
14 |
Correct |
12 ms |
340 KB |
correct |
15 |
Correct |
14 ms |
392 KB |
correct |
16 |
Correct |
14 ms |
340 KB |
correct |
17 |
Correct |
7 ms |
340 KB |
correct |
18 |
Correct |
3 ms |
296 KB |
correct |
19 |
Correct |
8 ms |
340 KB |
correct |
20 |
Correct |
9 ms |
372 KB |
correct |
21 |
Correct |
8 ms |
368 KB |
correct |
22 |
Correct |
6 ms |
304 KB |
correct |
23 |
Correct |
5 ms |
296 KB |
correct |
24 |
Correct |
5 ms |
340 KB |
correct |
25 |
Correct |
2 ms |
280 KB |
correct |
26 |
Correct |
5 ms |
340 KB |
correct |
27 |
Correct |
5 ms |
340 KB |
correct |
28 |
Correct |
3 ms |
212 KB |
correct |
29 |
Correct |
2 ms |
212 KB |
correct |
30 |
Correct |
4 ms |
296 KB |
correct |
31 |
Correct |
5 ms |
296 KB |
correct |
32 |
Correct |
5 ms |
348 KB |
correct |
33 |
Correct |
4 ms |
300 KB |
correct |
34 |
Correct |
2512 ms |
2512 KB |
correct |
35 |
Correct |
2021 ms |
2444 KB |
correct |
36 |
Correct |
1396 ms |
1764 KB |
correct |
37 |
Correct |
67 ms |
340 KB |
correct |
38 |
Correct |
1857 ms |
2492 KB |
correct |
39 |
Correct |
2049 ms |
2172 KB |
correct |
40 |
Correct |
1591 ms |
1752 KB |
correct |
41 |
Execution timed out |
3075 ms |
2516 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |