#include "simurgh.h"
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define N 520
using namespace std;
typedef pair<int, int> pii;
pii ed[N*N];
vector<pii> grafo[N];
vector<int> tree, T[N];
int cnt, grau[N], id[N][N], ans[N*N];;
int vis[N], n, x[N], filhos[N], pai[N], nivel[N], dfsnum[N], dfslow[N];
struct dsu{
int pai[N], peso[N];
int Find(int x){
if(x==pai[x]) return x;
return pai[x] = Find(pai[x]);
}
int join(int a, int b){
a = Find(a), b = Find(b);
if(a== b) return 0;
if(peso[a] > peso[b]) swap(a, b);
pai[a]=b;
if(peso[a]==peso[b])peso[b]++;
return 1;
}
void init(){
for(int i = 0; i <= n; i++){
pai[i]=i;
peso[i]=0;
}
}
} UF;
void dfs(int x){
dfsnum[x] = dfslow[x] = ++cnt;
vis[x] = 1;
for(auto v: grafo[x]){
if(!vis[v.f]){
tree.pb(v.s);
pai[v.f] = x;
nivel[v.f] = nivel[x] + 1;
T[x].pb(v.f);
T[v.f].pb(x);
dfs(v.f);
if(dfslow[v.f] > dfsnum[x]) ans[v.s] = 1;
dfslow[x]=min(dfslow[v.f], dfslow[x]);
}
else if(v.f != pai[x]) dfslow[x] = min(dfsnum[v.f], dfslow[x]);
}
}
vector<int> find_roads(int NN, vector<int> u, vector<int> v) {
// assert(u.size() == NN*(NN-1)/2);
if(NN == 2){
vector<int> ans;
for(int i = 0; i < sz(u); i++) ans.pb(i);
return ans;
}
n = NN;
for(int i = 0; i < sz(u); i++){
++u[i];++v[i];
grafo[u[i]].pb({v[i], i});
grafo[v[i]].pb({u[i], i});
ed[i] = {u[i], v[i]};
id[u[i]][v[i]] = id[v[i]][u[i]] = i;
}
dfs(1);
sort(all(tree));
int A = count_common_roads(tree);
for(int x = 1; x <= n; x++){
for(auto v: grafo[x]){
if(binary_search(all(tree), v.s) or v.f > x) continue;
int a = x, b = v.f;
if(nivel[a] < nivel[b]) swap(a, b);
vector<int> caras;
while(a != b){
caras.pb(id[a][pai[a]]);
a = pai[a];
}
int good = -1,tot=0;
for(auto w: caras)
if(ans[w] != 0) good = w,tot++;
if(tot == sz(caras)) continue;
if(good == -1){
vector<int> iguais;
for(auto w: caras){
vector<int> atual;
atual.pb(v.s);
for(auto t: tree){
if(t == w) continue;
atual.pb(t);
}
int X = count_common_roads(atual);
if(X == A) iguais.pb(w); // w = v.s
else if(X < A){
ans[w] = 1;
ans[v.s] = -1;
}
else{
ans[w] = -1;
ans[v.s] = 1;
}
}
if(ans[v.s] == 0) ans[v.s]=-1;
for(auto y: iguais) ans[y] = ans[v.s];
}
else{
vector<int> atual;
atual.pb(v.s);
for(auto t :tree){
if(t==good) continue;
atual.pb(t);
}
// T - Xgood + Xv
int X = count_common_roads(atual); // tira good e coloca v.s
if(X == A) ans[v.s] = ans[good];
else if(X > A) ans[v.s] = 1;
else ans[v.s] = -1;
for(auto w: caras){
if(ans[w] != 0) continue;
vector<int> atual;
atual.pb(v.s);
for(auto t: tree){
if(t == w) continue;
atual.pb(t);
}
int Y = count_common_roads(atual); // T - Xw + Xv
if(Y == X) ans[w] = ans[good];
else if(Y > X) ans[w] = -1;
else ans[w] = 1;
}
}
}
}
for(int i = 1; i <= n; i++){
vector<int> ed, lixos;
UF.init();
for(auto j: grafo[i]){
if(i == j.f) continue;
ed.pb(id[i][j.f]);
UF.join(i,j.f);
}
int aux = 0;
for(auto e: tree){
if(UF.join(u[e], v[e])){
aux += max(0, ans[e]);
ed.pb(e);
}
}
grau[i] = count_common_roads(ed)-aux;
}
vector<int> block(n+1);
while(true){
int achou = 0;
for(int i = 1; i <= n; i++){
if(block[i] or grau[i] - filhos[i] != 1) continue;
achou=1;
vector<int> caras;
block[i] = 1;
for(auto v: grafo[i]){
if(block[v.f]) continue;
caras.pb(v.f);
}
int ini = 0, fim = sz(caras), mid, best=-1;
while(fim >= ini){
mid = (ini+fim)/2;
UF.init();
vector<pii> arestas;
for(auto e: tree) arestas.pb({1, e});
for(int j = 0; j < mid; j++){
arestas.pb({0, id[i][caras[j]]});
}
sort(all(arestas));
vector<int> curr;
int aux=0;
set<int> usados;
for(int t = 0; t < sz(arestas); t++){
int a = ed[arestas[t].s].f, b = ed[arestas[t].s].s;
if(UF.join(a, b)){
curr.pb(arestas[t].s);
usados.insert(arestas[t].s);
}
else if(arestas[t].f == 1 ){
aux += max(0,ans[arestas[t].s]);
}
}
int C = count_common_roads(curr);
if(C - (A-aux) >= 1){
best = id[i][caras[mid-1]];
fim = mid - 1;
}
else ini = mid + 1;
}
int pai = ed[best].f;
if(pai==i)pai=ed[best].s;
filhos[pai]++;
ans[best] = 1;
}
if(!achou) break;
}
vector<int> resp;
for(int i = 0; i < u.size(); i++) if(ans[i]==1)resp.pb(i);
//cout<<"MY\n";
//for(auto e: resp) cout<<"resp | "<<e<<" | "<<u[e]<<" "<<v[e]<<"\n";
return resp;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:211:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
211 | for(int i = 0; i < u.size(); i++) if(ans[i]==1)resp.pb(i);
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
332 KB |
correct |
5 |
Correct |
1 ms |
332 KB |
correct |
6 |
Correct |
1 ms |
332 KB |
correct |
7 |
Correct |
1 ms |
332 KB |
correct |
8 |
Correct |
1 ms |
332 KB |
correct |
9 |
Correct |
1 ms |
332 KB |
correct |
10 |
Correct |
1 ms |
332 KB |
correct |
11 |
Correct |
1 ms |
332 KB |
correct |
12 |
Correct |
1 ms |
332 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
332 KB |
correct |
5 |
Correct |
1 ms |
332 KB |
correct |
6 |
Correct |
1 ms |
332 KB |
correct |
7 |
Correct |
1 ms |
332 KB |
correct |
8 |
Correct |
1 ms |
332 KB |
correct |
9 |
Correct |
1 ms |
332 KB |
correct |
10 |
Correct |
1 ms |
332 KB |
correct |
11 |
Correct |
1 ms |
332 KB |
correct |
12 |
Correct |
1 ms |
332 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
14 |
Correct |
4 ms |
476 KB |
correct |
15 |
Correct |
4 ms |
460 KB |
correct |
16 |
Correct |
4 ms |
472 KB |
correct |
17 |
Correct |
4 ms |
476 KB |
correct |
18 |
Correct |
3 ms |
472 KB |
correct |
19 |
Correct |
4 ms |
460 KB |
correct |
20 |
Correct |
4 ms |
460 KB |
correct |
21 |
Correct |
4 ms |
460 KB |
correct |
22 |
Correct |
3 ms |
460 KB |
correct |
23 |
Correct |
3 ms |
460 KB |
correct |
24 |
Correct |
3 ms |
460 KB |
correct |
25 |
Correct |
2 ms |
464 KB |
correct |
26 |
Correct |
3 ms |
460 KB |
correct |
27 |
Correct |
3 ms |
460 KB |
correct |
28 |
Correct |
3 ms |
460 KB |
correct |
29 |
Correct |
2 ms |
460 KB |
correct |
30 |
Correct |
3 ms |
468 KB |
correct |
31 |
Correct |
3 ms |
464 KB |
correct |
32 |
Correct |
3 ms |
464 KB |
correct |
33 |
Correct |
3 ms |
464 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
332 KB |
correct |
5 |
Correct |
1 ms |
332 KB |
correct |
6 |
Correct |
1 ms |
332 KB |
correct |
7 |
Correct |
1 ms |
332 KB |
correct |
8 |
Correct |
1 ms |
332 KB |
correct |
9 |
Correct |
1 ms |
332 KB |
correct |
10 |
Correct |
1 ms |
332 KB |
correct |
11 |
Correct |
1 ms |
332 KB |
correct |
12 |
Correct |
1 ms |
332 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
14 |
Correct |
4 ms |
476 KB |
correct |
15 |
Correct |
4 ms |
460 KB |
correct |
16 |
Correct |
4 ms |
472 KB |
correct |
17 |
Correct |
4 ms |
476 KB |
correct |
18 |
Correct |
3 ms |
472 KB |
correct |
19 |
Correct |
4 ms |
460 KB |
correct |
20 |
Correct |
4 ms |
460 KB |
correct |
21 |
Correct |
4 ms |
460 KB |
correct |
22 |
Correct |
3 ms |
460 KB |
correct |
23 |
Correct |
3 ms |
460 KB |
correct |
24 |
Correct |
3 ms |
460 KB |
correct |
25 |
Correct |
2 ms |
464 KB |
correct |
26 |
Correct |
3 ms |
460 KB |
correct |
27 |
Correct |
3 ms |
460 KB |
correct |
28 |
Correct |
3 ms |
460 KB |
correct |
29 |
Correct |
2 ms |
460 KB |
correct |
30 |
Correct |
3 ms |
468 KB |
correct |
31 |
Correct |
3 ms |
464 KB |
correct |
32 |
Correct |
3 ms |
464 KB |
correct |
33 |
Correct |
3 ms |
464 KB |
correct |
34 |
Correct |
131 ms |
2428 KB |
correct |
35 |
Correct |
128 ms |
2396 KB |
correct |
36 |
Correct |
111 ms |
2056 KB |
correct |
37 |
Correct |
43 ms |
844 KB |
correct |
38 |
Correct |
126 ms |
2372 KB |
correct |
39 |
Correct |
122 ms |
2232 KB |
correct |
40 |
Correct |
114 ms |
1996 KB |
correct |
41 |
Correct |
128 ms |
2416 KB |
correct |
42 |
Correct |
134 ms |
2372 KB |
correct |
43 |
Correct |
89 ms |
1844 KB |
correct |
44 |
Correct |
82 ms |
1500 KB |
correct |
45 |
Correct |
90 ms |
1612 KB |
correct |
46 |
Correct |
78 ms |
1356 KB |
correct |
47 |
Correct |
63 ms |
1156 KB |
correct |
48 |
Correct |
28 ms |
844 KB |
correct |
49 |
Correct |
39 ms |
844 KB |
correct |
50 |
Correct |
63 ms |
1164 KB |
correct |
51 |
Correct |
88 ms |
1624 KB |
correct |
52 |
Correct |
86 ms |
1540 KB |
correct |
53 |
Correct |
78 ms |
1356 KB |
correct |
54 |
Correct |
89 ms |
1844 KB |
correct |
55 |
Correct |
92 ms |
1612 KB |
correct |
56 |
Correct |
90 ms |
1632 KB |
correct |
57 |
Correct |
101 ms |
1624 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
419 ms |
5556 KB |
correct |
4 |
Correct |
705 ms |
7372 KB |
correct |
5 |
Correct |
707 ms |
7300 KB |
correct |
6 |
Correct |
711 ms |
7236 KB |
correct |
7 |
Correct |
715 ms |
7236 KB |
correct |
8 |
Correct |
767 ms |
7148 KB |
correct |
9 |
Correct |
712 ms |
7276 KB |
correct |
10 |
Correct |
699 ms |
7108 KB |
correct |
11 |
Correct |
704 ms |
7268 KB |
correct |
12 |
Correct |
730 ms |
7364 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
14 |
Correct |
712 ms |
7224 KB |
correct |
15 |
Correct |
705 ms |
7236 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
1 ms |
332 KB |
correct |
5 |
Correct |
1 ms |
332 KB |
correct |
6 |
Correct |
1 ms |
332 KB |
correct |
7 |
Correct |
1 ms |
332 KB |
correct |
8 |
Correct |
1 ms |
332 KB |
correct |
9 |
Correct |
1 ms |
332 KB |
correct |
10 |
Correct |
1 ms |
332 KB |
correct |
11 |
Correct |
1 ms |
332 KB |
correct |
12 |
Correct |
1 ms |
332 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
14 |
Correct |
4 ms |
476 KB |
correct |
15 |
Correct |
4 ms |
460 KB |
correct |
16 |
Correct |
4 ms |
472 KB |
correct |
17 |
Correct |
4 ms |
476 KB |
correct |
18 |
Correct |
3 ms |
472 KB |
correct |
19 |
Correct |
4 ms |
460 KB |
correct |
20 |
Correct |
4 ms |
460 KB |
correct |
21 |
Correct |
4 ms |
460 KB |
correct |
22 |
Correct |
3 ms |
460 KB |
correct |
23 |
Correct |
3 ms |
460 KB |
correct |
24 |
Correct |
3 ms |
460 KB |
correct |
25 |
Correct |
2 ms |
464 KB |
correct |
26 |
Correct |
3 ms |
460 KB |
correct |
27 |
Correct |
3 ms |
460 KB |
correct |
28 |
Correct |
3 ms |
460 KB |
correct |
29 |
Correct |
2 ms |
460 KB |
correct |
30 |
Correct |
3 ms |
468 KB |
correct |
31 |
Correct |
3 ms |
464 KB |
correct |
32 |
Correct |
3 ms |
464 KB |
correct |
33 |
Correct |
3 ms |
464 KB |
correct |
34 |
Correct |
131 ms |
2428 KB |
correct |
35 |
Correct |
128 ms |
2396 KB |
correct |
36 |
Correct |
111 ms |
2056 KB |
correct |
37 |
Correct |
43 ms |
844 KB |
correct |
38 |
Correct |
126 ms |
2372 KB |
correct |
39 |
Correct |
122 ms |
2232 KB |
correct |
40 |
Correct |
114 ms |
1996 KB |
correct |
41 |
Correct |
128 ms |
2416 KB |
correct |
42 |
Correct |
134 ms |
2372 KB |
correct |
43 |
Correct |
89 ms |
1844 KB |
correct |
44 |
Correct |
82 ms |
1500 KB |
correct |
45 |
Correct |
90 ms |
1612 KB |
correct |
46 |
Correct |
78 ms |
1356 KB |
correct |
47 |
Correct |
63 ms |
1156 KB |
correct |
48 |
Correct |
28 ms |
844 KB |
correct |
49 |
Correct |
39 ms |
844 KB |
correct |
50 |
Correct |
63 ms |
1164 KB |
correct |
51 |
Correct |
88 ms |
1624 KB |
correct |
52 |
Correct |
86 ms |
1540 KB |
correct |
53 |
Correct |
78 ms |
1356 KB |
correct |
54 |
Correct |
89 ms |
1844 KB |
correct |
55 |
Correct |
92 ms |
1612 KB |
correct |
56 |
Correct |
90 ms |
1632 KB |
correct |
57 |
Correct |
101 ms |
1624 KB |
correct |
58 |
Correct |
1 ms |
332 KB |
correct |
59 |
Correct |
1 ms |
332 KB |
correct |
60 |
Correct |
419 ms |
5556 KB |
correct |
61 |
Correct |
705 ms |
7372 KB |
correct |
62 |
Correct |
707 ms |
7300 KB |
correct |
63 |
Correct |
711 ms |
7236 KB |
correct |
64 |
Correct |
715 ms |
7236 KB |
correct |
65 |
Correct |
767 ms |
7148 KB |
correct |
66 |
Correct |
712 ms |
7276 KB |
correct |
67 |
Correct |
699 ms |
7108 KB |
correct |
68 |
Correct |
704 ms |
7268 KB |
correct |
69 |
Correct |
730 ms |
7364 KB |
correct |
70 |
Correct |
1 ms |
332 KB |
correct |
71 |
Correct |
712 ms |
7224 KB |
correct |
72 |
Correct |
705 ms |
7236 KB |
correct |
73 |
Correct |
1 ms |
332 KB |
correct |
74 |
Correct |
714 ms |
8360 KB |
correct |
75 |
Correct |
730 ms |
8024 KB |
correct |
76 |
Correct |
354 ms |
3720 KB |
correct |
77 |
Correct |
711 ms |
8088 KB |
correct |
78 |
Correct |
718 ms |
8004 KB |
correct |
79 |
Correct |
702 ms |
8132 KB |
correct |
80 |
Correct |
693 ms |
7888 KB |
correct |
81 |
Correct |
672 ms |
7312 KB |
correct |
82 |
Correct |
700 ms |
7884 KB |
correct |
83 |
Correct |
547 ms |
5100 KB |
correct |
84 |
Correct |
506 ms |
5640 KB |
correct |
85 |
Correct |
476 ms |
5360 KB |
correct |
86 |
Correct |
432 ms |
4080 KB |
correct |
87 |
Correct |
375 ms |
3484 KB |
correct |
88 |
Correct |
372 ms |
2956 KB |
correct |
89 |
Correct |
332 ms |
2756 KB |
correct |
90 |
Correct |
325 ms |
2748 KB |
correct |
91 |
Correct |
165 ms |
1484 KB |
correct |
92 |
Correct |
122 ms |
1476 KB |
correct |
93 |
Correct |
482 ms |
5380 KB |
correct |
94 |
Correct |
421 ms |
4004 KB |
correct |
95 |
Correct |
409 ms |
3936 KB |
correct |
96 |
Correct |
369 ms |
2712 KB |
correct |
97 |
Correct |
378 ms |
2828 KB |
correct |
98 |
Correct |
390 ms |
3404 KB |
correct |
99 |
Correct |
361 ms |
2844 KB |
correct |
100 |
Correct |
221 ms |
1740 KB |
correct |
101 |
Correct |
119 ms |
1500 KB |
correct |
102 |
Correct |
504 ms |
4692 KB |
correct |
103 |
Correct |
494 ms |
4596 KB |
correct |
104 |
Correct |
497 ms |
4576 KB |
correct |
105 |
Correct |
497 ms |
4552 KB |
correct |