# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
372290 |
2021-02-27T14:27:06 Z |
doowey |
Simurgh (IOI17_simurgh) |
C++14 |
|
240 ms |
12012 KB |
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int N = 500;
const int M = N * (N - 1) / 2;
vector<pii> T[N];
vector<pii> Q[N];
int dep[N];
pii low[N];
int in[N];
int edge[M];
int know[M];
vector<int> fq;
void dfs(int u, int pp){
low[u] = mp(dep[u], -1);
for(auto x : T[u]){
if(x.fi == pp) continue;
if(dep[x.fi] == -1){
in[x.fi]=x.se;
dep[x.fi]=dep[u]+1;
dfs(x.fi, u);
fq.push_back(x.se);
low[u] = min(low[u], low[x.fi]);
if(dep[u] < low[x.fi].fi){
know[x.se] = 1;
edge[x.se] = -1; // bridge
}
else{
edge[x.se] = 0; //
}
}
else{
edge[x.se] = 2; // these f*ck everything up
low[u] = min(low[u], mp(dep[x.fi], x.se));
}
}
}
vector<int> G[M];
int get(int ii, int jj){
vector<int> aq;
for(auto x : fq) if(x != ii) aq.push_back(x);
aq.push_back(jj);
return count_common_roads(aq);
}
vector<int> cyc;
bool vis[M];
void dfs1(int u){
vis[u]=true;
cyc.push_back(u);
for(auto x : G[u]){
if(!vis[x]){
dfs1(x);
}
}
}
int par[N];
int fin_node(int x){
if(par[x] == x) return x;
return par[x]=fin_node(par[x]);
}
bool unite(int a, int b){
a = fin_node(a);
b = fin_node(b);
if(a == b) return false;
par[a] = b;
return true;
}
int n;
vector<pii> saf;
vector<int>u,v;
void bins(int l, int r){
vector<int> E;
for(int i = 0 ; i < n; i ++ ){
par[i]=i;
}
int rem = 0;
for(int j = l ; j <= r; j ++ ){
E.push_back(saf[j].se);
unite(u[saf[j].se], v[saf[j].se]);
}
for(auto x : fq){
if(unite(u[x], v[x])){
rem += know[x];
E.push_back(x);
}
}
int sha = count_common_roads(E) - rem;
if(sha == 0) return;
if(l == r){
know[saf[l].se]=1;
return;
}
int mid = (l + r) / 2;
bins(l, mid);
bins(mid + 1, r);
}
vector<int> find_roads(int _n, vector<int> u_, vector<int> v_) {
n = _n;
u = u_;
v = v_;
int m = u.size();
for(int i = 0 ; i < m ; i ++ ){
T[u[i]].push_back(mp(v[i], i));
T[v[i]].push_back(mp(u[i], i));
edge[i] = -1;
know[i]=-1;
}
for(int i = 0 ; i < n; i ++ ){
dep[i] = -1;
}
dep[0]=0;
dfs(0,-1);
for(int i = 0 ; i < m ; i ++) {
if(dep[u[i]] > dep[v[i]])
swap(u[i], v[i]);
}
for(int i = 1; i < n; i ++ ){
edge[low[i].se] = 1;
}
int faf = count_common_roads(fq);
int nw;
int uu, vv;
int go;
for(int i = 0 ; i < m ; i ++ ){
if(edge[i] == 0){
uu = i;
vv = low[v[i]].se;
nw = get(uu, vv);
if(faf == nw){
G[uu].push_back(vv);
G[vv].push_back(uu);
}
else{
if(nw > faf){
know[vv]=1;
know[uu]=0;
}
else{
know[vv]=0;
know[uu]=1;
}
}
}
else if(edge[i] == 1){
vv = i;
go = v[i];
while(u[in[go]] != u[i]){
go = u[in[go]];
}
uu = in[go];
nw = get(uu, vv);
if(faf == nw){
G[uu].push_back(vv);
G[vv].push_back(uu);
}
else{
if(nw > faf){
know[vv]=1;
know[uu]=0;
}
else{
know[vv]=0;
know[uu]=1;
}
}
}
}
int val;
for(int i = 0 ; i < m ; i ++ ){
if(edge[i] == 0 || edge[i] == 1){
if(!vis[i]){
cyc.clear();
dfs1(i);
val = -1;
for(auto x : cyc){
if(know[x] != -1) val = know[x];
}
if(val == -1) val = 0;
for(auto x : cyc) know[x] = val;
}
}
}
vector<int> soln;
for(int i = 0 ; i < m ; i ++ ){
if(edge[i] == 2){
Q[u[i]].push_back(mp(v[i], i));
}
}
int cnt;
int cur;
for(int i = 0 ; i < n; i ++ ){
if(Q[i].empty()) continue;
saf = Q[i];
bins(0, (int)saf.size() - 1);
}
for(int i = 0 ; i < m ; i ++ ){
if(know[i] == 1) soln.push_back(i);
}
return soln;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:209:9: warning: unused variable 'cnt' [-Wunused-variable]
209 | int cnt;
| ^~~
simurgh.cpp:210:9: warning: unused variable 'cur' [-Wunused-variable]
210 | int cur;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3308 KB |
correct |
2 |
Correct |
2 ms |
3308 KB |
correct |
3 |
Correct |
3 ms |
3308 KB |
correct |
4 |
Correct |
3 ms |
3308 KB |
correct |
5 |
Correct |
2 ms |
3308 KB |
correct |
6 |
Correct |
2 ms |
3308 KB |
correct |
7 |
Correct |
3 ms |
3308 KB |
correct |
8 |
Correct |
3 ms |
3308 KB |
correct |
9 |
Correct |
2 ms |
3308 KB |
correct |
10 |
Correct |
3 ms |
3308 KB |
correct |
11 |
Correct |
3 ms |
3308 KB |
correct |
12 |
Correct |
3 ms |
3308 KB |
correct |
13 |
Correct |
2 ms |
3308 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3308 KB |
correct |
2 |
Correct |
2 ms |
3308 KB |
correct |
3 |
Correct |
3 ms |
3308 KB |
correct |
4 |
Correct |
3 ms |
3308 KB |
correct |
5 |
Correct |
2 ms |
3308 KB |
correct |
6 |
Correct |
2 ms |
3308 KB |
correct |
7 |
Correct |
3 ms |
3308 KB |
correct |
8 |
Correct |
3 ms |
3308 KB |
correct |
9 |
Correct |
2 ms |
3308 KB |
correct |
10 |
Correct |
3 ms |
3308 KB |
correct |
11 |
Correct |
3 ms |
3308 KB |
correct |
12 |
Correct |
3 ms |
3308 KB |
correct |
13 |
Correct |
2 ms |
3308 KB |
correct |
14 |
Correct |
4 ms |
3436 KB |
correct |
15 |
Correct |
4 ms |
3436 KB |
correct |
16 |
Correct |
4 ms |
3436 KB |
correct |
17 |
Correct |
4 ms |
3584 KB |
correct |
18 |
Correct |
3 ms |
3308 KB |
correct |
19 |
Correct |
4 ms |
3456 KB |
correct |
20 |
Correct |
4 ms |
3308 KB |
correct |
21 |
Correct |
4 ms |
3308 KB |
correct |
22 |
Correct |
3 ms |
3308 KB |
correct |
23 |
Correct |
3 ms |
3308 KB |
correct |
24 |
Correct |
3 ms |
3308 KB |
correct |
25 |
Correct |
3 ms |
3308 KB |
correct |
26 |
Correct |
3 ms |
3308 KB |
correct |
27 |
Correct |
3 ms |
3308 KB |
correct |
28 |
Correct |
3 ms |
3308 KB |
correct |
29 |
Correct |
3 ms |
3308 KB |
correct |
30 |
Correct |
3 ms |
3308 KB |
correct |
31 |
Correct |
3 ms |
3308 KB |
correct |
32 |
Correct |
3 ms |
3308 KB |
correct |
33 |
Correct |
3 ms |
3308 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3308 KB |
correct |
2 |
Correct |
2 ms |
3308 KB |
correct |
3 |
Correct |
3 ms |
3308 KB |
correct |
4 |
Correct |
3 ms |
3308 KB |
correct |
5 |
Correct |
2 ms |
3308 KB |
correct |
6 |
Correct |
2 ms |
3308 KB |
correct |
7 |
Correct |
3 ms |
3308 KB |
correct |
8 |
Correct |
3 ms |
3308 KB |
correct |
9 |
Correct |
2 ms |
3308 KB |
correct |
10 |
Correct |
3 ms |
3308 KB |
correct |
11 |
Correct |
3 ms |
3308 KB |
correct |
12 |
Correct |
3 ms |
3308 KB |
correct |
13 |
Correct |
2 ms |
3308 KB |
correct |
14 |
Correct |
4 ms |
3436 KB |
correct |
15 |
Correct |
4 ms |
3436 KB |
correct |
16 |
Correct |
4 ms |
3436 KB |
correct |
17 |
Correct |
4 ms |
3584 KB |
correct |
18 |
Correct |
3 ms |
3308 KB |
correct |
19 |
Correct |
4 ms |
3456 KB |
correct |
20 |
Correct |
4 ms |
3308 KB |
correct |
21 |
Correct |
4 ms |
3308 KB |
correct |
22 |
Correct |
3 ms |
3308 KB |
correct |
23 |
Correct |
3 ms |
3308 KB |
correct |
24 |
Correct |
3 ms |
3308 KB |
correct |
25 |
Correct |
3 ms |
3308 KB |
correct |
26 |
Correct |
3 ms |
3308 KB |
correct |
27 |
Correct |
3 ms |
3308 KB |
correct |
28 |
Correct |
3 ms |
3308 KB |
correct |
29 |
Correct |
3 ms |
3308 KB |
correct |
30 |
Correct |
3 ms |
3308 KB |
correct |
31 |
Correct |
3 ms |
3308 KB |
correct |
32 |
Correct |
3 ms |
3308 KB |
correct |
33 |
Correct |
3 ms |
3308 KB |
correct |
34 |
Correct |
46 ms |
5376 KB |
correct |
35 |
Correct |
45 ms |
5228 KB |
correct |
36 |
Correct |
40 ms |
4844 KB |
correct |
37 |
Correct |
15 ms |
3436 KB |
correct |
38 |
Correct |
48 ms |
5356 KB |
correct |
39 |
Correct |
49 ms |
5100 KB |
correct |
40 |
Correct |
46 ms |
4972 KB |
correct |
41 |
Correct |
50 ms |
5356 KB |
correct |
42 |
Correct |
34 ms |
5356 KB |
correct |
43 |
Correct |
21 ms |
4588 KB |
correct |
44 |
Correct |
18 ms |
4224 KB |
correct |
45 |
Correct |
19 ms |
4332 KB |
correct |
46 |
Correct |
19 ms |
4076 KB |
correct |
47 |
Correct |
13 ms |
3692 KB |
correct |
48 |
Correct |
5 ms |
3308 KB |
correct |
49 |
Correct |
9 ms |
3436 KB |
correct |
50 |
Correct |
14 ms |
3692 KB |
correct |
51 |
Correct |
19 ms |
4204 KB |
correct |
52 |
Correct |
18 ms |
4076 KB |
correct |
53 |
Correct |
18 ms |
4076 KB |
correct |
54 |
Correct |
20 ms |
4460 KB |
correct |
55 |
Correct |
19 ms |
4204 KB |
correct |
56 |
Correct |
19 ms |
4204 KB |
correct |
57 |
Correct |
18 ms |
4204 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3308 KB |
correct |
2 |
Correct |
2 ms |
3308 KB |
correct |
3 |
Correct |
145 ms |
8556 KB |
correct |
4 |
Correct |
215 ms |
11884 KB |
correct |
5 |
Correct |
232 ms |
11884 KB |
correct |
6 |
Correct |
100 ms |
11884 KB |
correct |
7 |
Correct |
171 ms |
11952 KB |
correct |
8 |
Correct |
186 ms |
12012 KB |
correct |
9 |
Correct |
240 ms |
12012 KB |
correct |
10 |
Correct |
226 ms |
11884 KB |
correct |
11 |
Correct |
229 ms |
11884 KB |
correct |
12 |
Correct |
225 ms |
11884 KB |
correct |
13 |
Correct |
2 ms |
3308 KB |
correct |
14 |
Correct |
179 ms |
11884 KB |
correct |
15 |
Correct |
226 ms |
12012 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3308 KB |
correct |
2 |
Correct |
2 ms |
3308 KB |
correct |
3 |
Correct |
3 ms |
3308 KB |
correct |
4 |
Correct |
3 ms |
3308 KB |
correct |
5 |
Correct |
2 ms |
3308 KB |
correct |
6 |
Correct |
2 ms |
3308 KB |
correct |
7 |
Correct |
3 ms |
3308 KB |
correct |
8 |
Correct |
3 ms |
3308 KB |
correct |
9 |
Correct |
2 ms |
3308 KB |
correct |
10 |
Correct |
3 ms |
3308 KB |
correct |
11 |
Correct |
3 ms |
3308 KB |
correct |
12 |
Correct |
3 ms |
3308 KB |
correct |
13 |
Correct |
2 ms |
3308 KB |
correct |
14 |
Correct |
4 ms |
3436 KB |
correct |
15 |
Correct |
4 ms |
3436 KB |
correct |
16 |
Correct |
4 ms |
3436 KB |
correct |
17 |
Correct |
4 ms |
3584 KB |
correct |
18 |
Correct |
3 ms |
3308 KB |
correct |
19 |
Correct |
4 ms |
3456 KB |
correct |
20 |
Correct |
4 ms |
3308 KB |
correct |
21 |
Correct |
4 ms |
3308 KB |
correct |
22 |
Correct |
3 ms |
3308 KB |
correct |
23 |
Correct |
3 ms |
3308 KB |
correct |
24 |
Correct |
3 ms |
3308 KB |
correct |
25 |
Correct |
3 ms |
3308 KB |
correct |
26 |
Correct |
3 ms |
3308 KB |
correct |
27 |
Correct |
3 ms |
3308 KB |
correct |
28 |
Correct |
3 ms |
3308 KB |
correct |
29 |
Correct |
3 ms |
3308 KB |
correct |
30 |
Correct |
3 ms |
3308 KB |
correct |
31 |
Correct |
3 ms |
3308 KB |
correct |
32 |
Correct |
3 ms |
3308 KB |
correct |
33 |
Correct |
3 ms |
3308 KB |
correct |
34 |
Correct |
46 ms |
5376 KB |
correct |
35 |
Correct |
45 ms |
5228 KB |
correct |
36 |
Correct |
40 ms |
4844 KB |
correct |
37 |
Correct |
15 ms |
3436 KB |
correct |
38 |
Correct |
48 ms |
5356 KB |
correct |
39 |
Correct |
49 ms |
5100 KB |
correct |
40 |
Correct |
46 ms |
4972 KB |
correct |
41 |
Correct |
50 ms |
5356 KB |
correct |
42 |
Correct |
34 ms |
5356 KB |
correct |
43 |
Correct |
21 ms |
4588 KB |
correct |
44 |
Correct |
18 ms |
4224 KB |
correct |
45 |
Correct |
19 ms |
4332 KB |
correct |
46 |
Correct |
19 ms |
4076 KB |
correct |
47 |
Correct |
13 ms |
3692 KB |
correct |
48 |
Correct |
5 ms |
3308 KB |
correct |
49 |
Correct |
9 ms |
3436 KB |
correct |
50 |
Correct |
14 ms |
3692 KB |
correct |
51 |
Correct |
19 ms |
4204 KB |
correct |
52 |
Correct |
18 ms |
4076 KB |
correct |
53 |
Correct |
18 ms |
4076 KB |
correct |
54 |
Correct |
20 ms |
4460 KB |
correct |
55 |
Correct |
19 ms |
4204 KB |
correct |
56 |
Correct |
19 ms |
4204 KB |
correct |
57 |
Correct |
18 ms |
4204 KB |
correct |
58 |
Correct |
3 ms |
3308 KB |
correct |
59 |
Correct |
2 ms |
3308 KB |
correct |
60 |
Correct |
145 ms |
8556 KB |
correct |
61 |
Correct |
215 ms |
11884 KB |
correct |
62 |
Correct |
232 ms |
11884 KB |
correct |
63 |
Correct |
100 ms |
11884 KB |
correct |
64 |
Correct |
171 ms |
11952 KB |
correct |
65 |
Correct |
186 ms |
12012 KB |
correct |
66 |
Correct |
240 ms |
12012 KB |
correct |
67 |
Correct |
226 ms |
11884 KB |
correct |
68 |
Correct |
229 ms |
11884 KB |
correct |
69 |
Correct |
225 ms |
11884 KB |
correct |
70 |
Correct |
2 ms |
3308 KB |
correct |
71 |
Correct |
179 ms |
11884 KB |
correct |
72 |
Correct |
226 ms |
12012 KB |
correct |
73 |
Correct |
3 ms |
3308 KB |
correct |
74 |
Incorrect |
224 ms |
12012 KB |
WA in grader: NO |
75 |
Halted |
0 ms |
0 KB |
- |