#include<iostream>
#include<vector>
#include<unordered_set>
#include<unordered_map>
#include"simurgh.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define N 250
vector<P> g[N];
unordered_set<int> vis;
vector<int> edges;
int blg[N];
void dfs(ll x,ll eid,ll root){
if(vis.find(x)==vis.end())return;
vis.insert(x);
if(~eid)edges.push_back(eid);
blg[x]=root;
for(auto y:g[x]){
dfs(y.first,y.second,root);
}
}
vector<int> find_roads(int n,vector<int> u,vector<int> v){
for(int i=0;i<n-1;i++){
g[u[i]].push_back(make_pair(v[i],i));
g[v[i]].push_back(make_pair(u[i],i));
}
vector<int> ans;
for(int i=0;i<n;i++){
edges.clear();
vis.clear();
vis.insert(i);
for(int j=0;j<n;j++){
dfs(j,-1,j);
}
unordered_map<ll,vector<int> >mas;
for(auto e:g[i]){
mas[blg[e.first]].push_back(e.second);
}
for(auto v:mas){
for(auto vv:mas){
if(v!=vv)edges.push_back(vv.second[0]);
}
int ma=-1;
unordered_map<int,int> sav;
for(auto e:v.second){
edges.push_back(e);
if(edges.size()!=n-1)cout<<1/0<<endl;
sav[e]=count_common_roads(edges);
chmax(ma,sav[e]);
edges.pop_back();
}
for(auto e:v.second){
if(sav[e]==ma)ans.push_back(e);
}
for(auto vv:mas){
if(v!=vv)edges.pop_back();
}
}
}
return ans;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:52:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(edges.size()!=n-1)cout<<1/0<<endl;
~~~~~~~~~~~~^~~~~
simurgh.cpp:52:31: warning: division by zero [-Wdiv-by-zero]
if(edges.size()!=n-1)cout<<1/0<<endl;
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
376 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
376 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
376 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
252 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
376 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |