#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
//int count_common_roads(vector<int> &r);
const int N = 507;
const int M = N * (N - 1) / 2 + 1;
mt19937 mt;
int rnd(int mod){
return mt() % mod;
}
struct edge{
int from, to, idx;
edge();
edge(int from, int to, int idx){
this->from = from;
this->to = to;
this->idx = idx;
}
};
vector<int> adj[N];
vector<edge> ev;
int m, par[N], sz[N];
void find_par(int u){
if(u == par[u]){
return;
}
find_par(par[u]);
par[u] = par[par[u]];
}
bool unite(int u, int v){
find_par(u);
find_par(v);
if(par[u] == par[v]){
return false;
}
if(sz[par[u]] < sz[par[v]]){
swap(u, v);
}
sz[par[u]] += sz[par[v]];
par[par[v]] = par[u];
return true;
}
vector<int> find_roads(int n, vector<int> u, vector<int> v){
m = (int)u.size();
for(int i = 0; i < m; i++){
//adj[ u[i] ].push_back(v[i]);
//adj[ v[i] ].push_back(u[i]);
ev.push_back(edge(u[i], v[i], i));
}
while(true){
for(int i = 0; i < n; i++){
par[i] = i;
sz[i] = 1;
}
random_shuffle(ev.begin(), ev.end(), rnd);
vector<int> v;
for(edge e: ev){
if(unite(e.from, e.to)){
v.push_back(e.idx);
if(v.size() == n - 1){
//break;
}
}
}
if(count_common_roads(v) == n - 1){
return v;
}
}
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:80:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v.size() == n - 1){
~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
376 KB |
correct |
2 |
Correct |
3 ms |
376 KB |
correct |
3 |
Correct |
40 ms |
376 KB |
correct |
4 |
Correct |
3 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
376 KB |
correct |
6 |
Correct |
8 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
372 KB |
correct |
8 |
Correct |
2 ms |
376 KB |
correct |
9 |
Correct |
2 ms |
376 KB |
correct |
10 |
Correct |
2 ms |
376 KB |
correct |
11 |
Correct |
2 ms |
376 KB |
correct |
12 |
Correct |
3 ms |
376 KB |
correct |
13 |
Correct |
12 ms |
256 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
376 KB |
correct |
2 |
Correct |
3 ms |
376 KB |
correct |
3 |
Correct |
40 ms |
376 KB |
correct |
4 |
Correct |
3 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
376 KB |
correct |
6 |
Correct |
8 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
372 KB |
correct |
8 |
Correct |
2 ms |
376 KB |
correct |
9 |
Correct |
2 ms |
376 KB |
correct |
10 |
Correct |
2 ms |
376 KB |
correct |
11 |
Correct |
2 ms |
376 KB |
correct |
12 |
Correct |
3 ms |
376 KB |
correct |
13 |
Correct |
12 ms |
256 KB |
correct |
14 |
Incorrect |
1612 ms |
444 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
376 KB |
correct |
2 |
Correct |
3 ms |
376 KB |
correct |
3 |
Correct |
40 ms |
376 KB |
correct |
4 |
Correct |
3 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
376 KB |
correct |
6 |
Correct |
8 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
372 KB |
correct |
8 |
Correct |
2 ms |
376 KB |
correct |
9 |
Correct |
2 ms |
376 KB |
correct |
10 |
Correct |
2 ms |
376 KB |
correct |
11 |
Correct |
2 ms |
376 KB |
correct |
12 |
Correct |
3 ms |
376 KB |
correct |
13 |
Correct |
12 ms |
256 KB |
correct |
14 |
Incorrect |
1612 ms |
444 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Incorrect |
34 ms |
376 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
376 KB |
correct |
2 |
Correct |
3 ms |
376 KB |
correct |
3 |
Correct |
40 ms |
376 KB |
correct |
4 |
Correct |
3 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
376 KB |
correct |
6 |
Correct |
8 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
372 KB |
correct |
8 |
Correct |
2 ms |
376 KB |
correct |
9 |
Correct |
2 ms |
376 KB |
correct |
10 |
Correct |
2 ms |
376 KB |
correct |
11 |
Correct |
2 ms |
376 KB |
correct |
12 |
Correct |
3 ms |
376 KB |
correct |
13 |
Correct |
12 ms |
256 KB |
correct |
14 |
Incorrect |
1612 ms |
444 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |