#include <bits/stdc++.h>
#define pb push_back
#include "simurgh.h"
using namespace std;
/*
static int MAXQ = 30000;
static int n, m, q = 0;
static vector<int> u, v;
static vector<bool> goal;
static void wrong_answer() {
printf("NO\n");
exit(0);
}
static bool is_valid(const vector<int>& r) {
if(int(r.size()) != n - 1)
return false;
for(int i = 0; i < n - 1; i++)
if (r[i] < 0 || r[i] >= m)
return false;
return true;
}
static int _count_common_roads_internal(const vector<int>& r) {
if(!is_valid(r))
wrong_answer();
int common = 0;
for(int i = 0; i < n - 1; i++) {
bool is_common = goal[r[i]];
if (is_common)
common++;
}
return common;
}
int count_common_roads(const vector<int>& r) {
q++;
if(q > MAXQ)
wrong_answer();
return _count_common_roads_internal(r);
}
*/
const int MAXN = 5e2 + 5;
vector<int> par(MAXN);
vector<pair<int, int> > adj[MAXN];
int fnd(int a){
if(a == par[a]) return a;
return par[a] = fnd(par[a]);
}
void merge(int a, int b){
a = fnd(a), b = fnd(b);
par[b] = a;
}
vector<int> find_roads(int n, vector<int> u, vector<int> v){
vector<int> r;
int m = u.size();
vector<int> ok(m);
for(int i = 0; i < m; i++){
adj[u[i]].pb({v[i], i});
adj[v[i]].pb({u[i], i});
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
par[j] = j;
}
vector<int> ottree;
for(int j = 0; j < n; j++){
if(j == i) continue;
for(auto itr: adj[j]){
if(itr.first == i) continue;
if(fnd(j) == fnd(itr.first)) continue;
ottree.pb(itr.second);
merge(j, itr.first);
}
}
// diğerlerini olabildiğince mergeledik
// a tane grup olsun a-1 tanesini random seçip a. gruptakileri dene büyük olanları tagle sonra random birini seçip a-1. için aynı şeyi yap
vector<pair<int, int> > edge;
set<int> df;
for(auto itr: adj[i]){
edge.pb({fnd(itr.first), itr.second});
df.insert(fnd(itr.first));
}
sort(edge.begin(), edge.end());
vector<int> groups[df.size()];
int x = *(df.begin());
int ind = 0;
for(auto itr: edge){
if(itr.first != x){
ind++;
x = itr.first;
}
groups[ind].pb(itr.second);
}
for(int g = 0; g < df.size(); g++){
if(groups[g].size() == 1){
ok[groups[g][0]] = 1;
continue;
}
for(int g2 = 0; g2 < df.size(); g2++){
if(g2 == g) continue;
ottree.pb(groups[g2][0]);
}
vector<pair<int, int> > vals;
int mx = 0;
for(auto itr: groups[g]){
ottree.pb(itr);
int cnt = count_common_roads(ottree);
vals.pb({cnt, itr});
mx = max(mx, cnt);
ottree.pop_back();
}
for(int j = 0; j < vals.size(); j++){
if(vals[j].first == mx) ok[vals[j].second] = 1;
}
for(int g2 = 0; g2 < df.size(); g2++){
if(g2 == g) continue;
ottree.pop_back();
}
}
}
for(int i = 0; i < m; i++){
if(ok[i]) r.pb(i);
}
return r;
}
/*
int main() {
assert(2 == scanf("%d %d", &n, &m));
u.resize(m);
v.resize(m);
for(int i = 0; i < m; i++)
assert(2 == scanf("%d %d", &u[i], &v[i]));
goal.resize(m, false);
for(int i = 0; i < n - 1; i++) {
int id;
assert(1 == scanf("%d", &id));
goal[id] = true;
}
vector<int> res = find_roads(n, u, v);
for(auto itr: res){
cout<<itr<<" ";
}
cout<<endl;
if(_count_common_roads_internal(res) != n - 1)
wrong_answer();
printf("YES\n");
return 0;
}
*/
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:112:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int g = 0; g < df.size(); g++){
| ~~^~~~~~~~~~~
simurgh.cpp:118:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | for(int g2 = 0; g2 < df.size(); g2++){
| ~~~^~~~~~~~~~~
simurgh.cpp:133:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
133 | for(int j = 0; j < vals.size(); j++){
| ~~^~~~~~~~~~~~~
simurgh.cpp:137:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | for(int g2 = 0; g2 < df.size(); g2++){
| ~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
correct |
2 |
Correct |
1 ms |
336 KB |
correct |
3 |
Correct |
1 ms |
504 KB |
correct |
4 |
Correct |
1 ms |
336 KB |
correct |
5 |
Correct |
1 ms |
336 KB |
correct |
6 |
Correct |
1 ms |
336 KB |
correct |
7 |
Correct |
1 ms |
336 KB |
correct |
8 |
Correct |
1 ms |
336 KB |
correct |
9 |
Correct |
1 ms |
336 KB |
correct |
10 |
Correct |
1 ms |
336 KB |
correct |
11 |
Correct |
1 ms |
336 KB |
correct |
12 |
Correct |
1 ms |
504 KB |
correct |
13 |
Correct |
1 ms |
336 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
correct |
2 |
Correct |
1 ms |
336 KB |
correct |
3 |
Correct |
1 ms |
504 KB |
correct |
4 |
Correct |
1 ms |
336 KB |
correct |
5 |
Correct |
1 ms |
336 KB |
correct |
6 |
Correct |
1 ms |
336 KB |
correct |
7 |
Correct |
1 ms |
336 KB |
correct |
8 |
Correct |
1 ms |
336 KB |
correct |
9 |
Correct |
1 ms |
336 KB |
correct |
10 |
Correct |
1 ms |
336 KB |
correct |
11 |
Correct |
1 ms |
336 KB |
correct |
12 |
Correct |
1 ms |
504 KB |
correct |
13 |
Correct |
1 ms |
336 KB |
correct |
14 |
Correct |
4 ms |
336 KB |
correct |
15 |
Correct |
3 ms |
336 KB |
correct |
16 |
Correct |
3 ms |
336 KB |
correct |
17 |
Correct |
3 ms |
336 KB |
correct |
18 |
Correct |
2 ms |
336 KB |
correct |
19 |
Correct |
3 ms |
516 KB |
correct |
20 |
Correct |
2 ms |
336 KB |
correct |
21 |
Correct |
3 ms |
336 KB |
correct |
22 |
Correct |
3 ms |
336 KB |
correct |
23 |
Correct |
2 ms |
336 KB |
correct |
24 |
Correct |
2 ms |
336 KB |
correct |
25 |
Correct |
1 ms |
336 KB |
correct |
26 |
Correct |
2 ms |
336 KB |
correct |
27 |
Correct |
2 ms |
336 KB |
correct |
28 |
Correct |
2 ms |
336 KB |
correct |
29 |
Correct |
1 ms |
336 KB |
correct |
30 |
Correct |
2 ms |
336 KB |
correct |
31 |
Correct |
2 ms |
336 KB |
correct |
32 |
Correct |
3 ms |
336 KB |
correct |
33 |
Correct |
2 ms |
336 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
correct |
2 |
Correct |
1 ms |
336 KB |
correct |
3 |
Correct |
1 ms |
504 KB |
correct |
4 |
Correct |
1 ms |
336 KB |
correct |
5 |
Correct |
1 ms |
336 KB |
correct |
6 |
Correct |
1 ms |
336 KB |
correct |
7 |
Correct |
1 ms |
336 KB |
correct |
8 |
Correct |
1 ms |
336 KB |
correct |
9 |
Correct |
1 ms |
336 KB |
correct |
10 |
Correct |
1 ms |
336 KB |
correct |
11 |
Correct |
1 ms |
336 KB |
correct |
12 |
Correct |
1 ms |
504 KB |
correct |
13 |
Correct |
1 ms |
336 KB |
correct |
14 |
Correct |
4 ms |
336 KB |
correct |
15 |
Correct |
3 ms |
336 KB |
correct |
16 |
Correct |
3 ms |
336 KB |
correct |
17 |
Correct |
3 ms |
336 KB |
correct |
18 |
Correct |
2 ms |
336 KB |
correct |
19 |
Correct |
3 ms |
516 KB |
correct |
20 |
Correct |
2 ms |
336 KB |
correct |
21 |
Correct |
3 ms |
336 KB |
correct |
22 |
Correct |
3 ms |
336 KB |
correct |
23 |
Correct |
2 ms |
336 KB |
correct |
24 |
Correct |
2 ms |
336 KB |
correct |
25 |
Correct |
1 ms |
336 KB |
correct |
26 |
Correct |
2 ms |
336 KB |
correct |
27 |
Correct |
2 ms |
336 KB |
correct |
28 |
Correct |
2 ms |
336 KB |
correct |
29 |
Correct |
1 ms |
336 KB |
correct |
30 |
Correct |
2 ms |
336 KB |
correct |
31 |
Correct |
2 ms |
336 KB |
correct |
32 |
Correct |
3 ms |
336 KB |
correct |
33 |
Correct |
2 ms |
336 KB |
correct |
34 |
Incorrect |
101 ms |
1616 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
508 KB |
correct |
2 |
Correct |
1 ms |
336 KB |
correct |
3 |
Incorrect |
83 ms |
3680 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
correct |
2 |
Correct |
1 ms |
336 KB |
correct |
3 |
Correct |
1 ms |
504 KB |
correct |
4 |
Correct |
1 ms |
336 KB |
correct |
5 |
Correct |
1 ms |
336 KB |
correct |
6 |
Correct |
1 ms |
336 KB |
correct |
7 |
Correct |
1 ms |
336 KB |
correct |
8 |
Correct |
1 ms |
336 KB |
correct |
9 |
Correct |
1 ms |
336 KB |
correct |
10 |
Correct |
1 ms |
336 KB |
correct |
11 |
Correct |
1 ms |
336 KB |
correct |
12 |
Correct |
1 ms |
504 KB |
correct |
13 |
Correct |
1 ms |
336 KB |
correct |
14 |
Correct |
4 ms |
336 KB |
correct |
15 |
Correct |
3 ms |
336 KB |
correct |
16 |
Correct |
3 ms |
336 KB |
correct |
17 |
Correct |
3 ms |
336 KB |
correct |
18 |
Correct |
2 ms |
336 KB |
correct |
19 |
Correct |
3 ms |
516 KB |
correct |
20 |
Correct |
2 ms |
336 KB |
correct |
21 |
Correct |
3 ms |
336 KB |
correct |
22 |
Correct |
3 ms |
336 KB |
correct |
23 |
Correct |
2 ms |
336 KB |
correct |
24 |
Correct |
2 ms |
336 KB |
correct |
25 |
Correct |
1 ms |
336 KB |
correct |
26 |
Correct |
2 ms |
336 KB |
correct |
27 |
Correct |
2 ms |
336 KB |
correct |
28 |
Correct |
2 ms |
336 KB |
correct |
29 |
Correct |
1 ms |
336 KB |
correct |
30 |
Correct |
2 ms |
336 KB |
correct |
31 |
Correct |
2 ms |
336 KB |
correct |
32 |
Correct |
3 ms |
336 KB |
correct |
33 |
Correct |
2 ms |
336 KB |
correct |
34 |
Incorrect |
101 ms |
1616 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |