#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define MAXN 300
int N,a,b;
vpi V[MAXN];
vpi edgeList;
vi res,cur;
vpi tmp;
int p[MAXN];
int lowlink[MAXN], depth[MAXN];
int par(int x){return (x==p[x])?x:p[x] = par(p[x]);}
vi bridges;
void dfs(int x,int p){
// cout<<"DFS "<<x<<' '<<p<<'\n';
lowlink[x] = depth[x];
for (auto v : V[x])if(v.f!=p){
if (depth[v.f] != -1){
lowlink[x] = min(lowlink[x], lowlink[v.f]);
continue;
}
depth[v.f] = depth[x]+1;
dfs(v.f,x);
lowlink[x] = min(lowlink[x], lowlink[v.f]);
}
}
bool isBridge(int x, int y){
if (lowlink[x]<=depth[y]&&depth[x]>depth[y])return 0;
if (lowlink[y]<=depth[x]&&depth[y]>depth[x])return 0;
// cout<<x<<' '<<y<<'\n';
return 1;
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
N=n;
for (int i=0;i<SZ(u);++i){
a=u[i];b=v[i];
V[a].pb(b,i);V[b].pb(a,i);
edgeList.pb(a,b);
}
a=1;
memset(depth,-1,sizeof(depth));
depth[0]=0;
dfs(0,0);
// for (int i=0;i<N;++i)cout<<depth[i]<<' '<<lowlink[i]<<'\n';
if (N <= 240){
for (int i=0;i<SZ(u);++i){
int a=edgeList[i].f;
int b=edgeList[i].s;
if (isBridge(a,b))bridges.pb(i);
}
// for (auto i : bridges)cout<<i<<'\n';
if (SZ(bridges) == N-1)return bridges;
for (int i=0;i<N;++i){
// We want to find all edges with index to a bigger node
for (int j=0;j<N;++j)p[j]=j;
cur.clear();
tmp.clear();
for (auto it : bridges){
cur.pb(it);
p[par(edgeList[it].f)] = par(edgeList[it].s);
}
for (int j=0;j<SZ(edgeList);++j){
pi it = edgeList[j];
if (it.f == i || it.s == i)continue;
if (par(it.f) == par(it.s))continue;
p[par(it.f)] = par(it.s);
cur.pb(j);
}
for (auto x : V[i]){
if (isBridge(i,x.f))continue;
if (i>x.f)continue;
cur.pb(x.s);
// for (auto i : cur)cout<<i<<' ' ;cout<<'\n';
int t = count_common_roads(cur);
tmp.pb(x.s,t);
cur.pop_back();
}
// cout<<"Current "<<i<<'\n';
// for (auto x : tmp)cout<<x.f<<' '<<x.s<<'\n';
int hh = 0;
// cout<<"V:";for (auto v:res)cout<<v<<' ';cout<<'\n';
bool gay=1;
for (auto t : res){
pi it = edgeList[t];
if (it.f == i || it.s == i){
cur.pb(t);
hh = count_common_roads(cur);
gay=0;
break;
}
}
if (gay){
int ll = 0;
for (auto x:tmp)ll = max(ll,x.s);
for (auto x :tmp)if(x.s==ll)res.pb(x.f);
continue;
}
for (auto x : tmp){
if (x.s == hh)res.pb(x.f);
}
// for (auto x :tmp)cout<<x.f<<' '<<x.s<<'\n';
// for (auto x:res)cout<<x<<' ';cout<<'\n';
}
for (auto i : bridges)res.pb(i);
sort(ALL(res));
res.resize(unique(ALL(res)) - res.begin());
// assert(SZ(res) == N-1);
return res;
}
assert(SZ(u) == N*(N-1)/2);
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:133:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
252 KB |
correct |
3 |
Correct |
2 ms |
364 KB |
correct |
4 |
Correct |
2 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
376 KB |
correct |
6 |
Correct |
2 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
376 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 |
256 KB |
correct |
12 |
Correct |
2 ms |
376 KB |
correct |
13 |
Correct |
2 ms |
376 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
252 KB |
correct |
3 |
Correct |
2 ms |
364 KB |
correct |
4 |
Correct |
2 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
376 KB |
correct |
6 |
Correct |
2 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
376 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 |
256 KB |
correct |
12 |
Correct |
2 ms |
376 KB |
correct |
13 |
Correct |
2 ms |
376 KB |
correct |
14 |
Correct |
4 ms |
376 KB |
correct |
15 |
Correct |
4 ms |
376 KB |
correct |
16 |
Correct |
4 ms |
376 KB |
correct |
17 |
Correct |
4 ms |
376 KB |
correct |
18 |
Correct |
3 ms |
376 KB |
correct |
19 |
Correct |
7 ms |
376 KB |
correct |
20 |
Correct |
5 ms |
380 KB |
correct |
21 |
Correct |
4 ms |
376 KB |
correct |
22 |
Correct |
4 ms |
376 KB |
correct |
23 |
Correct |
13 ms |
420 KB |
correct |
24 |
Correct |
4 ms |
376 KB |
correct |
25 |
Correct |
3 ms |
376 KB |
correct |
26 |
Correct |
4 ms |
376 KB |
correct |
27 |
Correct |
4 ms |
376 KB |
correct |
28 |
Correct |
3 ms |
376 KB |
correct |
29 |
Correct |
3 ms |
376 KB |
correct |
30 |
Correct |
4 ms |
376 KB |
correct |
31 |
Correct |
3 ms |
376 KB |
correct |
32 |
Correct |
3 ms |
376 KB |
correct |
33 |
Correct |
3 ms |
376 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
252 KB |
correct |
3 |
Correct |
2 ms |
364 KB |
correct |
4 |
Correct |
2 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
376 KB |
correct |
6 |
Correct |
2 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
376 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 |
256 KB |
correct |
12 |
Correct |
2 ms |
376 KB |
correct |
13 |
Correct |
2 ms |
376 KB |
correct |
14 |
Correct |
4 ms |
376 KB |
correct |
15 |
Correct |
4 ms |
376 KB |
correct |
16 |
Correct |
4 ms |
376 KB |
correct |
17 |
Correct |
4 ms |
376 KB |
correct |
18 |
Correct |
3 ms |
376 KB |
correct |
19 |
Correct |
7 ms |
376 KB |
correct |
20 |
Correct |
5 ms |
380 KB |
correct |
21 |
Correct |
4 ms |
376 KB |
correct |
22 |
Correct |
4 ms |
376 KB |
correct |
23 |
Correct |
13 ms |
420 KB |
correct |
24 |
Correct |
4 ms |
376 KB |
correct |
25 |
Correct |
3 ms |
376 KB |
correct |
26 |
Correct |
4 ms |
376 KB |
correct |
27 |
Correct |
4 ms |
376 KB |
correct |
28 |
Correct |
3 ms |
376 KB |
correct |
29 |
Correct |
3 ms |
376 KB |
correct |
30 |
Correct |
4 ms |
376 KB |
correct |
31 |
Correct |
3 ms |
376 KB |
correct |
32 |
Correct |
3 ms |
376 KB |
correct |
33 |
Correct |
3 ms |
376 KB |
correct |
34 |
Correct |
237 ms |
1784 KB |
correct |
35 |
Correct |
236 ms |
1656 KB |
correct |
36 |
Correct |
167 ms |
1528 KB |
correct |
37 |
Correct |
18 ms |
376 KB |
correct |
38 |
Correct |
241 ms |
1784 KB |
correct |
39 |
Correct |
218 ms |
1660 KB |
correct |
40 |
Correct |
161 ms |
1528 KB |
correct |
41 |
Correct |
242 ms |
1784 KB |
correct |
42 |
Correct |
250 ms |
1656 KB |
correct |
43 |
Correct |
129 ms |
1272 KB |
correct |
44 |
Correct |
108 ms |
1016 KB |
correct |
45 |
Correct |
123 ms |
1052 KB |
correct |
46 |
Correct |
97 ms |
1016 KB |
correct |
47 |
Correct |
43 ms |
632 KB |
correct |
48 |
Correct |
8 ms |
376 KB |
correct |
49 |
Correct |
16 ms |
376 KB |
correct |
50 |
Correct |
44 ms |
632 KB |
correct |
51 |
Correct |
124 ms |
1020 KB |
correct |
52 |
Correct |
106 ms |
1016 KB |
correct |
53 |
Correct |
97 ms |
1084 KB |
correct |
54 |
Correct |
126 ms |
1272 KB |
correct |
55 |
Correct |
111 ms |
1144 KB |
correct |
56 |
Correct |
109 ms |
1256 KB |
correct |
57 |
Correct |
106 ms |
1144 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
correct |
2 |
Correct |
2 ms |
376 KB |
correct |
3 |
Runtime error |
26 ms |
3576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
correct |
2 |
Correct |
2 ms |
252 KB |
correct |
3 |
Correct |
2 ms |
364 KB |
correct |
4 |
Correct |
2 ms |
376 KB |
correct |
5 |
Correct |
2 ms |
376 KB |
correct |
6 |
Correct |
2 ms |
376 KB |
correct |
7 |
Correct |
2 ms |
376 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 |
256 KB |
correct |
12 |
Correct |
2 ms |
376 KB |
correct |
13 |
Correct |
2 ms |
376 KB |
correct |
14 |
Correct |
4 ms |
376 KB |
correct |
15 |
Correct |
4 ms |
376 KB |
correct |
16 |
Correct |
4 ms |
376 KB |
correct |
17 |
Correct |
4 ms |
376 KB |
correct |
18 |
Correct |
3 ms |
376 KB |
correct |
19 |
Correct |
7 ms |
376 KB |
correct |
20 |
Correct |
5 ms |
380 KB |
correct |
21 |
Correct |
4 ms |
376 KB |
correct |
22 |
Correct |
4 ms |
376 KB |
correct |
23 |
Correct |
13 ms |
420 KB |
correct |
24 |
Correct |
4 ms |
376 KB |
correct |
25 |
Correct |
3 ms |
376 KB |
correct |
26 |
Correct |
4 ms |
376 KB |
correct |
27 |
Correct |
4 ms |
376 KB |
correct |
28 |
Correct |
3 ms |
376 KB |
correct |
29 |
Correct |
3 ms |
376 KB |
correct |
30 |
Correct |
4 ms |
376 KB |
correct |
31 |
Correct |
3 ms |
376 KB |
correct |
32 |
Correct |
3 ms |
376 KB |
correct |
33 |
Correct |
3 ms |
376 KB |
correct |
34 |
Correct |
237 ms |
1784 KB |
correct |
35 |
Correct |
236 ms |
1656 KB |
correct |
36 |
Correct |
167 ms |
1528 KB |
correct |
37 |
Correct |
18 ms |
376 KB |
correct |
38 |
Correct |
241 ms |
1784 KB |
correct |
39 |
Correct |
218 ms |
1660 KB |
correct |
40 |
Correct |
161 ms |
1528 KB |
correct |
41 |
Correct |
242 ms |
1784 KB |
correct |
42 |
Correct |
250 ms |
1656 KB |
correct |
43 |
Correct |
129 ms |
1272 KB |
correct |
44 |
Correct |
108 ms |
1016 KB |
correct |
45 |
Correct |
123 ms |
1052 KB |
correct |
46 |
Correct |
97 ms |
1016 KB |
correct |
47 |
Correct |
43 ms |
632 KB |
correct |
48 |
Correct |
8 ms |
376 KB |
correct |
49 |
Correct |
16 ms |
376 KB |
correct |
50 |
Correct |
44 ms |
632 KB |
correct |
51 |
Correct |
124 ms |
1020 KB |
correct |
52 |
Correct |
106 ms |
1016 KB |
correct |
53 |
Correct |
97 ms |
1084 KB |
correct |
54 |
Correct |
126 ms |
1272 KB |
correct |
55 |
Correct |
111 ms |
1144 KB |
correct |
56 |
Correct |
109 ms |
1256 KB |
correct |
57 |
Correct |
106 ms |
1144 KB |
correct |
58 |
Correct |
2 ms |
256 KB |
correct |
59 |
Correct |
2 ms |
376 KB |
correct |
60 |
Runtime error |
26 ms |
3576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
61 |
Halted |
0 ms |
0 KB |
- |