#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]){
if(ok[itr] == 0){
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;
else 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] == 1) 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:135: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]
135 | for(int j = 0; j < vals.size(); j++){
| ~~^~~~~~~~~~~~~
simurgh.cpp:140:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for(int g2 = 0; g2 < df.size(); g2++){
| ~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
correct |
2 |
Incorrect |
1 ms |
336 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |