# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1058425 |
2024-08-14T09:56:30 Z |
shenfe1 |
Simurgh (IOI17_simurgh) |
C++17 |
|
215 ms |
29388 KB |
#include <bits/stdc++.h>
#include "simurgh.h"
#pragma GCC optimize("Ofast")
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define sz(s) (int)s.size()
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int MAX=2e5+10;
struct dsu{
int f[MAX];
void init(int n){
for(int i=0;i<n;i++)f[i]=i;
}
int get(int v){
return (f[v]==v?v:f[v]=get(f[v]));
}
void unite(int a,int b){
a=get(a),b=get(b);
f[a]=b;
}
}d;
int n;
vector<pii> g[MAX];
vector<int> u,v;
int is1[MAX],is0[MAX],dn[MAX];
int pr[MAX],dep[MAX];
set<int> st;
void dfs(int st){
queue<int> q;
q.push(st);
while(!q.empty()){
int v=q.front();
q.pop();
for(auto to:g[v]){
if(pr[v]==to.S)continue;
dep[to.F]=dep[v]+1;
pr[to.F]=to.S;
q.push(to.F);
}
}
}
int cq=1;
vector<int> vc(set<int> &st){
vector<int> res;
for(int i:st)res.pb(i);
return res;
}
int add(vector<int> &vec){
int CNT=0;
d.init(n);
vector<int> x;
for(int i:vec){
x.pb(i);
d.unite(u[i],v[i]);
}
for(int i:st){
if(d.get(u[i])!=d.get(v[i])){
CNT+=is1[i];
d.unite(u[i],v[i]);
x.pb(i);
}
}
cq++;
assert(cq<=8000);
return count_common_roads(x)-CNT;
}
vector<int> find_roads(int N,vector<int> U,vector<int> V){
n=N;
u=U;
v=V;
vector<int> e;
d.init(n);
for(int i=0;i<sz(U);i++){
if(d.get(U[i])!=d.get(V[i])){
d.unite(U[i],V[i]);
g[U[i]].pb({V[i],i});
g[V[i]].pb({U[i],i});
st.insert(i);
}
else e.pb(i);
}
for(int i=0;i<sz(U);i++)dn[i]=1;
for(int i=0;i<n;i++)pr[i]=-1;
dfs(0);
int cnt=count_common_roads(vc(st));
for(int num:e){
int a=U[num],b=V[num];
vector<int> canzam;
int allv=0;
int CNT=0;
while(a!=b){
CNT++;
if(CNT>N){
return vector<int>(n,-1);
}
if(dep[a]>dep[b]){
canzam.pb(pr[a]);
if(U[pr[a]]==a)a=V[pr[a]];
else a=U[pr[a]];
}
else{
canzam.pb(pr[b]);
if(U[pr[b]]==b)b=V[pr[b]];
else b=U[pr[b]];
}
}
int ok=0;
int canEdge=-1;
for(int edge:canzam){
if(dn[edge])allv=1;
if(is1[edge]){
ok=1;
canEdge=edge;
}
else if(is0[edge]){
ok=2;
canEdge=edge;
}
}
if(!allv)continue;
if(ok==0){
for(int edge:canzam){
assert(dn[edge]);
st.erase(edge);
st.insert(num);
cq++;
int ncnt=count_common_roads(vc(st));
if(ncnt<cnt){
dn[edge]=0;
is1[edge]=1;
dn[num]=0;
is0[num]=1;
}
else if(ncnt>cnt){
dn[edge]=0;
is0[edge]=1;
dn[num]=0;
is1[num]=1;
}
st.insert(edge);
st.erase(num);
}
if(dn[num]){
dn[num]=0;
is0[num]=1;
for(int edge:canzam){
dn[edge]=0;
is0[edge]=1;
}
}
else{
for(int edge:canzam){
if(dn[edge]){
dn[edge]=0;
is0[edge]=is0[num];
is1[edge]=is1[num];
}
}
}
}
else if(ok==1){
st.erase(canEdge);
st.insert(num);
int ncnt=count_common_roads(vc(st));
cq++;
st.insert(canEdge);
st.erase(num);
dn[num]=0;
if(ncnt==cnt){
is1[num]=1;
}
else{
is0[num]=1;
}
}
else{
st.erase(canEdge);
st.insert(num);
int ncnt=count_common_roads(vc(st));
cq++;
st.insert(canEdge);
st.erase(num);
dn[num]=0;
if(ncnt==cnt){
is0[num]=1;
}
else{
is1[num]=1;
}
}
for(int edge:canzam){
if(dn[edge]){
dn[edge]=0;
st.insert(num);
st.erase(edge);
cq++;
int ncnt=count_common_roads(vc(st));
st.erase(num);
st.insert(edge);
if(ncnt==cnt){
is0[edge]=is0[num];
is1[edge]=is1[num];
}
else{
is0[edge]=1-is0[num];
is1[edge]=1-is1[num];
}
}
}
}
assert(cq<=2*n+1);
for(int edge:st){
if(dn[edge]){
dn[edge]=0;
is1[edge]=1;
}
}
for(int i=0;i<n;i++){
g[i].clear();
}
for(int i=0;i<sz(u);i++){
g[u[i]].pb({v[i],i});
g[v[i]].pb({u[i],i});
}
for(int i=0;i<n;i++){
vector<int> vec;
for(auto to:g[i]){
if(!st.count(to.S))vec.pb(to.S);
}
int cnt=add(vec);
for(int j=1;j<=cnt;j++){
int l=0,r=sz(g[i])-1,res=sz(g[i])-1;
while(l<=r){
int mid=(l+r)/2;
vector<int> vec;
for(int j=0;j<=mid;j++){
if(!st.count(g[i][j].S))vec.pb(g[i][j].S);
}
if(add(vec)>=j){
r=mid-1;
res=mid;
}
else l=mid+1;
}
is1[g[i][res].S]=1;
}
}
vector<int> ans;
for(int i=0;i<sz(u);i++)if(is1[i])ans.pb(i);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
correct |
2 |
Correct |
1 ms |
8796 KB |
correct |
3 |
Correct |
1 ms |
8796 KB |
correct |
4 |
Correct |
1 ms |
8796 KB |
correct |
5 |
Correct |
1 ms |
8792 KB |
correct |
6 |
Correct |
1 ms |
8796 KB |
correct |
7 |
Correct |
1 ms |
8796 KB |
correct |
8 |
Correct |
1 ms |
8796 KB |
correct |
9 |
Correct |
1 ms |
8796 KB |
correct |
10 |
Correct |
1 ms |
8796 KB |
correct |
11 |
Correct |
1 ms |
9048 KB |
correct |
12 |
Correct |
1 ms |
8796 KB |
correct |
13 |
Correct |
1 ms |
8892 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
correct |
2 |
Correct |
1 ms |
8796 KB |
correct |
3 |
Correct |
1 ms |
8796 KB |
correct |
4 |
Correct |
1 ms |
8796 KB |
correct |
5 |
Correct |
1 ms |
8792 KB |
correct |
6 |
Correct |
1 ms |
8796 KB |
correct |
7 |
Correct |
1 ms |
8796 KB |
correct |
8 |
Correct |
1 ms |
8796 KB |
correct |
9 |
Correct |
1 ms |
8796 KB |
correct |
10 |
Correct |
1 ms |
8796 KB |
correct |
11 |
Correct |
1 ms |
9048 KB |
correct |
12 |
Correct |
1 ms |
8796 KB |
correct |
13 |
Correct |
1 ms |
8892 KB |
correct |
14 |
Correct |
2 ms |
8796 KB |
correct |
15 |
Correct |
3 ms |
8792 KB |
correct |
16 |
Correct |
2 ms |
8796 KB |
correct |
17 |
Correct |
2 ms |
8796 KB |
correct |
18 |
Correct |
2 ms |
8796 KB |
correct |
19 |
Correct |
2 ms |
8884 KB |
correct |
20 |
Correct |
2 ms |
8792 KB |
correct |
21 |
Correct |
3 ms |
8796 KB |
correct |
22 |
Correct |
1 ms |
8796 KB |
correct |
23 |
Correct |
1 ms |
8796 KB |
correct |
24 |
Correct |
2 ms |
8796 KB |
correct |
25 |
Correct |
1 ms |
8796 KB |
correct |
26 |
Correct |
1 ms |
8796 KB |
correct |
27 |
Correct |
1 ms |
8796 KB |
correct |
28 |
Correct |
1 ms |
8796 KB |
correct |
29 |
Correct |
1 ms |
8796 KB |
correct |
30 |
Correct |
1 ms |
8796 KB |
correct |
31 |
Correct |
1 ms |
8796 KB |
correct |
32 |
Correct |
1 ms |
8796 KB |
correct |
33 |
Correct |
1 ms |
8796 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
correct |
2 |
Correct |
1 ms |
8796 KB |
correct |
3 |
Correct |
1 ms |
8796 KB |
correct |
4 |
Correct |
1 ms |
8796 KB |
correct |
5 |
Correct |
1 ms |
8792 KB |
correct |
6 |
Correct |
1 ms |
8796 KB |
correct |
7 |
Correct |
1 ms |
8796 KB |
correct |
8 |
Correct |
1 ms |
8796 KB |
correct |
9 |
Correct |
1 ms |
8796 KB |
correct |
10 |
Correct |
1 ms |
8796 KB |
correct |
11 |
Correct |
1 ms |
9048 KB |
correct |
12 |
Correct |
1 ms |
8796 KB |
correct |
13 |
Correct |
1 ms |
8892 KB |
correct |
14 |
Correct |
2 ms |
8796 KB |
correct |
15 |
Correct |
3 ms |
8792 KB |
correct |
16 |
Correct |
2 ms |
8796 KB |
correct |
17 |
Correct |
2 ms |
8796 KB |
correct |
18 |
Correct |
2 ms |
8796 KB |
correct |
19 |
Correct |
2 ms |
8884 KB |
correct |
20 |
Correct |
2 ms |
8792 KB |
correct |
21 |
Correct |
3 ms |
8796 KB |
correct |
22 |
Correct |
1 ms |
8796 KB |
correct |
23 |
Correct |
1 ms |
8796 KB |
correct |
24 |
Correct |
2 ms |
8796 KB |
correct |
25 |
Correct |
1 ms |
8796 KB |
correct |
26 |
Correct |
1 ms |
8796 KB |
correct |
27 |
Correct |
1 ms |
8796 KB |
correct |
28 |
Correct |
1 ms |
8796 KB |
correct |
29 |
Correct |
1 ms |
8796 KB |
correct |
30 |
Correct |
1 ms |
8796 KB |
correct |
31 |
Correct |
1 ms |
8796 KB |
correct |
32 |
Correct |
1 ms |
8796 KB |
correct |
33 |
Correct |
1 ms |
8796 KB |
correct |
34 |
Correct |
51 ms |
10076 KB |
correct |
35 |
Correct |
50 ms |
10076 KB |
correct |
36 |
Correct |
44 ms |
9816 KB |
correct |
37 |
Correct |
15 ms |
8796 KB |
correct |
38 |
Correct |
51 ms |
10092 KB |
correct |
39 |
Correct |
46 ms |
10076 KB |
correct |
40 |
Correct |
41 ms |
9816 KB |
correct |
41 |
Correct |
47 ms |
10072 KB |
correct |
42 |
Correct |
45 ms |
10076 KB |
correct |
43 |
Correct |
9 ms |
9560 KB |
correct |
44 |
Correct |
8 ms |
9308 KB |
correct |
45 |
Correct |
9 ms |
9436 KB |
correct |
46 |
Correct |
7 ms |
9308 KB |
correct |
47 |
Correct |
5 ms |
9052 KB |
correct |
48 |
Correct |
3 ms |
8796 KB |
correct |
49 |
Correct |
4 ms |
8796 KB |
correct |
50 |
Correct |
5 ms |
9052 KB |
correct |
51 |
Correct |
8 ms |
9604 KB |
correct |
52 |
Correct |
8 ms |
9496 KB |
correct |
53 |
Correct |
7 ms |
9308 KB |
correct |
54 |
Correct |
9 ms |
9564 KB |
correct |
55 |
Correct |
14 ms |
9564 KB |
correct |
56 |
Correct |
12 ms |
9404 KB |
correct |
57 |
Correct |
11 ms |
9556 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
correct |
2 |
Correct |
1 ms |
8796 KB |
correct |
3 |
Correct |
157 ms |
12800 KB |
correct |
4 |
Runtime error |
215 ms |
29388 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
correct |
2 |
Correct |
1 ms |
8796 KB |
correct |
3 |
Correct |
1 ms |
8796 KB |
correct |
4 |
Correct |
1 ms |
8796 KB |
correct |
5 |
Correct |
1 ms |
8792 KB |
correct |
6 |
Correct |
1 ms |
8796 KB |
correct |
7 |
Correct |
1 ms |
8796 KB |
correct |
8 |
Correct |
1 ms |
8796 KB |
correct |
9 |
Correct |
1 ms |
8796 KB |
correct |
10 |
Correct |
1 ms |
8796 KB |
correct |
11 |
Correct |
1 ms |
9048 KB |
correct |
12 |
Correct |
1 ms |
8796 KB |
correct |
13 |
Correct |
1 ms |
8892 KB |
correct |
14 |
Correct |
2 ms |
8796 KB |
correct |
15 |
Correct |
3 ms |
8792 KB |
correct |
16 |
Correct |
2 ms |
8796 KB |
correct |
17 |
Correct |
2 ms |
8796 KB |
correct |
18 |
Correct |
2 ms |
8796 KB |
correct |
19 |
Correct |
2 ms |
8884 KB |
correct |
20 |
Correct |
2 ms |
8792 KB |
correct |
21 |
Correct |
3 ms |
8796 KB |
correct |
22 |
Correct |
1 ms |
8796 KB |
correct |
23 |
Correct |
1 ms |
8796 KB |
correct |
24 |
Correct |
2 ms |
8796 KB |
correct |
25 |
Correct |
1 ms |
8796 KB |
correct |
26 |
Correct |
1 ms |
8796 KB |
correct |
27 |
Correct |
1 ms |
8796 KB |
correct |
28 |
Correct |
1 ms |
8796 KB |
correct |
29 |
Correct |
1 ms |
8796 KB |
correct |
30 |
Correct |
1 ms |
8796 KB |
correct |
31 |
Correct |
1 ms |
8796 KB |
correct |
32 |
Correct |
1 ms |
8796 KB |
correct |
33 |
Correct |
1 ms |
8796 KB |
correct |
34 |
Correct |
51 ms |
10076 KB |
correct |
35 |
Correct |
50 ms |
10076 KB |
correct |
36 |
Correct |
44 ms |
9816 KB |
correct |
37 |
Correct |
15 ms |
8796 KB |
correct |
38 |
Correct |
51 ms |
10092 KB |
correct |
39 |
Correct |
46 ms |
10076 KB |
correct |
40 |
Correct |
41 ms |
9816 KB |
correct |
41 |
Correct |
47 ms |
10072 KB |
correct |
42 |
Correct |
45 ms |
10076 KB |
correct |
43 |
Correct |
9 ms |
9560 KB |
correct |
44 |
Correct |
8 ms |
9308 KB |
correct |
45 |
Correct |
9 ms |
9436 KB |
correct |
46 |
Correct |
7 ms |
9308 KB |
correct |
47 |
Correct |
5 ms |
9052 KB |
correct |
48 |
Correct |
3 ms |
8796 KB |
correct |
49 |
Correct |
4 ms |
8796 KB |
correct |
50 |
Correct |
5 ms |
9052 KB |
correct |
51 |
Correct |
8 ms |
9604 KB |
correct |
52 |
Correct |
8 ms |
9496 KB |
correct |
53 |
Correct |
7 ms |
9308 KB |
correct |
54 |
Correct |
9 ms |
9564 KB |
correct |
55 |
Correct |
14 ms |
9564 KB |
correct |
56 |
Correct |
12 ms |
9404 KB |
correct |
57 |
Correct |
11 ms |
9556 KB |
correct |
58 |
Correct |
1 ms |
8792 KB |
correct |
59 |
Correct |
1 ms |
8796 KB |
correct |
60 |
Correct |
157 ms |
12800 KB |
correct |
61 |
Runtime error |
215 ms |
29388 KB |
Execution killed with signal 6 |
62 |
Halted |
0 ms |
0 KB |
- |