#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ld long double
/*
4 6
0 1
0 2
0 3
1 2
1 3
2 3
0 1 5
*/
int count_common_roads(const vector<int>& r);
int N;
set<pair<int,int> > p[600];
vector<int> grafo(int pos){
vector<int> v;
vector<bool> vis(N+2,0);
queue<pair<int,int> >q;
for(int i=0;i<N;i++){
if(vis[i] || i==pos)continue;
q.push({i,-1});
while(!q.empty()){
auto &[pp,idx]=q.front();
q.pop();
if(vis[pp])continue;
vis[pp]=1;
if(idx!=-1)v.push_back(idx);
for(auto x:p[pp]){
if(x.first!=pos)q.push({x.first,x.second});
}
}
}
return v;
}
vector<int> ordine;
void ord(){
vector<bool> vis(N,0);
queue<int>q;
q.push(0);
while(!q.empty()){
int pp=q.front();
q.pop();
if(vis[pp])continue;
vis[pp]=1;
ordine.push_back(pp);
for(auto x:p[pp]){
q.push(x.first);
}
}
reverse(ordine.begin(),ordine.end());
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v){
N=n;
for(int i=0;i<u.size();i++){
p[u[i]].insert({v[i],i});
p[v[i]].insert({u[i],i});
}
vector<int> ans;
ord();
vector<int> arco(N+10,-1);
for(int qq=0;qq<N;qq++){
int i=ordine[qq];
auto x=grafo(i);
for(int j=0;j<qq;j++)x.push_back(arco[ordine[j]]);
int ma=0;
vector<int> k;
for(auto y:p[i]){
x.push_back(y.second);
k.push_back(count_common_roads(x));
x.pop_back();
ma=max(ma,k.back());
}
int rr=0;
for(auto j:p[i]){
if(k[rr]==ma){
ans.push_back(j.second);
arco[i]=j.second;
}
rr++;
}
for(auto &[a,b]:p[i]){
p[a].erase({i,b});
}
p[i].clear();
}
sort(ans.begin(),ans.end());
ans.resize(unique(ans.begin(),ans.end())-ans.begin());
return ans;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> grafo(int)':
simurgh.cpp:29:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | auto &[pp,idx]=q.front();
| ^
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=0;i<u.size();i++){
| ~^~~~~~~~~
simurgh.cpp:87:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
87 | for(auto &[a,b]:p[i]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Incorrect |
0 ms |
384 KB |
WA in grader: NO |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |