# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
831761 |
2023-08-20T13:44:24 Z |
Rafi22 |
Simurgh (IOI17_simurgh) |
C++14 |
|
151 ms |
6868 KB |
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define st first
#define nd second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
int inf=1000000007;
ll infl=1000000000000000007;
const int N=507,M=507*507;
int U[M],V[M];
int n;
vector<pair<int,int>>G[N];
int odw[N],c;
int o[N],id[N];
vector<int>st;
int val[M];
void dfs(int v)
{
odw[v]=++c;
for(auto [u,i]:G[v])
{
if(!odw[u])
{
o[u]=v;
id[u]=i;
st.pb(i);
dfs(u);
}
}
}
int get(int x)
{
vector<int>Q;
for(auto y:st) if(y!=x) Q.pb(y);
return count_common_roads(Q);
}
void dfs1(int v)
{
odw[v]=++c;
for(auto [u,i]:G[v])
{
if(!odw[u]) dfs1(u);
else if(odw[u]<odw[v]&&u!=o[v])
{
vector<int>X={i};
st.pb(i);
int p=-1,x=v;
while(x!=u)
{
if(val[id[x]]) p=id[x];
else X.pb(id[x]);
x=o[x];
}
if(sz(X)==1)
{
st.pop_back();
continue;
}
if(p==-1)
{
vector<pair<int,int>>W;
int mx=-inf;
for(auto x:X)
{
int k=get(x);
mx=max(mx,k);
W.pb({k,x});
}
for(auto [k,x]:W)
{
if(k<mx) val[x]=2;
else val[x]=1;
}
}
else
{
for(auto x:X)
{
int c1=get(p),c2=get(x);
if(c1==c2) val[x]=val[p];
else if(c1<c2) val[x]=1;
else val[x]=2;
}
}
st.pop_back();
}
}
if(!val[id[v]]) val[id[v]]=2;
}
bool was[M];
vector<int>co[N];
int r[N];
int Find(int v)
{
if(r[v]==v) return v;
return r[v]=Find(r[v]);
}
void Union(int v,int u)
{
u=Find(u),v=Find(v);
r[u]=v;
}
int ile;
int qry(vector<int>W)
{
vector<int>Q;
for(int i=0;i<n;i++) r[i]=i;
for(auto x:W)
{
Union(U[x],V[x]);
Q.pb(x);
}
int k=ile;
for(auto x:st)
{
if(Find(U[x])==Find(V[x])) k-=val[x]-1;
else
{
Union(U[x],V[x]);
Q.pb(x);
}
}
return count_common_roads(Q)-k;
}
vector<int>find_roads(int nn,vector<int>uu,vector<int>vv)
{
n=nn;
int m=sz(uu);
for(int i=0;i<m;i++)
{
U[i]=uu[i];
V[i]=vv[i];
if(U[i]>V[i]) swap(U[i],V[i]);
G[U[i]].pb({V[i],i});
G[V[i]].pb({U[i],i});
}
dfs(0);
memset(odw,0,sizeof odw);
dfs1(0);
for(auto x:st) was[x]=1;
for(int i=0;i<m;i++)
{
if(!was[i]) co[U[i]].pb(i);
}
ile=count_common_roads(st);
for(int i=0;i<n;i++)
{
vector<int>Q;
for(auto x:co[i]) Q.pb(x);
int deg=qry(Q);
for(int j=1;j<=deg;j++)
{
int l=0,r=sz(co[i])-1,sr,p;
while(l<=r)
{
sr=(l+r)/2;
Q.clear();
for(int k=0;k<=sr;k++) Q.pb(co[i][k]);
if(qry(Q)>=j)
{
r=sr-1;
p=sr;
}
else l=sr+1;
}
val[co[i][p]]=2;
}
}
vector<int>ans;
for(int i=0;i<m;i++) if(val[i]==2) ans.pb(i);
return ans;
}
/*
int main()
{
vector<int>X=find_roads(4,{0, 0, 0, 1, 1, 2},{1, 2, 3, 2, 3, 3});
return 0;
}*/
Compilation message
simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:31:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
31 | for(auto [u,i]:G[v])
| ^
simurgh.cpp: In function 'void dfs1(int)':
simurgh.cpp:53:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
53 | for(auto [u,i]:G[v])
| ^
simurgh.cpp:82:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
82 | for(auto [k,x]:W)
| ^
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:185:15: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
185 | val[co[i][p]]=2;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
340 KB |
correct |
4 |
Correct |
0 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
0 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
340 KB |
correct |
4 |
Correct |
0 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
0 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
14 |
Correct |
1 ms |
340 KB |
correct |
15 |
Correct |
1 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
1 ms |
340 KB |
correct |
20 |
Correct |
1 ms |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
340 KB |
correct |
4 |
Correct |
0 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
0 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
14 |
Correct |
1 ms |
340 KB |
correct |
15 |
Correct |
1 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
1 ms |
340 KB |
correct |
20 |
Correct |
1 ms |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
34 |
Correct |
24 ms |
1896 KB |
correct |
35 |
Correct |
24 ms |
1824 KB |
correct |
36 |
Correct |
20 ms |
1580 KB |
correct |
37 |
Correct |
6 ms |
468 KB |
correct |
38 |
Correct |
25 ms |
1812 KB |
correct |
39 |
Correct |
22 ms |
1772 KB |
correct |
40 |
Correct |
20 ms |
1492 KB |
correct |
41 |
Correct |
23 ms |
1912 KB |
correct |
42 |
Correct |
23 ms |
1888 KB |
correct |
43 |
Correct |
10 ms |
1236 KB |
correct |
44 |
Correct |
9 ms |
980 KB |
correct |
45 |
Correct |
10 ms |
1056 KB |
correct |
46 |
Correct |
9 ms |
980 KB |
correct |
47 |
Correct |
6 ms |
668 KB |
correct |
48 |
Correct |
2 ms |
340 KB |
correct |
49 |
Correct |
4 ms |
468 KB |
correct |
50 |
Correct |
6 ms |
596 KB |
correct |
51 |
Correct |
12 ms |
1132 KB |
correct |
52 |
Correct |
9 ms |
956 KB |
correct |
53 |
Correct |
8 ms |
980 KB |
correct |
54 |
Correct |
11 ms |
1232 KB |
correct |
55 |
Correct |
11 ms |
1132 KB |
correct |
56 |
Correct |
11 ms |
1108 KB |
correct |
57 |
Correct |
11 ms |
1056 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
1 ms |
340 KB |
correct |
3 |
Correct |
79 ms |
4816 KB |
correct |
4 |
Correct |
135 ms |
6764 KB |
correct |
5 |
Correct |
151 ms |
6868 KB |
correct |
6 |
Correct |
131 ms |
6772 KB |
correct |
7 |
Correct |
129 ms |
6768 KB |
correct |
8 |
Correct |
129 ms |
6732 KB |
correct |
9 |
Correct |
141 ms |
6704 KB |
correct |
10 |
Correct |
134 ms |
6716 KB |
correct |
11 |
Correct |
132 ms |
6628 KB |
correct |
12 |
Correct |
135 ms |
6664 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
14 |
Correct |
132 ms |
6708 KB |
correct |
15 |
Correct |
139 ms |
6748 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
0 ms |
340 KB |
correct |
4 |
Correct |
0 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
0 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
14 |
Correct |
1 ms |
340 KB |
correct |
15 |
Correct |
1 ms |
340 KB |
correct |
16 |
Correct |
1 ms |
340 KB |
correct |
17 |
Correct |
1 ms |
340 KB |
correct |
18 |
Correct |
1 ms |
340 KB |
correct |
19 |
Correct |
1 ms |
340 KB |
correct |
20 |
Correct |
1 ms |
340 KB |
correct |
21 |
Correct |
1 ms |
340 KB |
correct |
22 |
Correct |
1 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
1 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
1 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
340 KB |
correct |
31 |
Correct |
1 ms |
340 KB |
correct |
32 |
Correct |
1 ms |
340 KB |
correct |
33 |
Correct |
1 ms |
340 KB |
correct |
34 |
Correct |
24 ms |
1896 KB |
correct |
35 |
Correct |
24 ms |
1824 KB |
correct |
36 |
Correct |
20 ms |
1580 KB |
correct |
37 |
Correct |
6 ms |
468 KB |
correct |
38 |
Correct |
25 ms |
1812 KB |
correct |
39 |
Correct |
22 ms |
1772 KB |
correct |
40 |
Correct |
20 ms |
1492 KB |
correct |
41 |
Correct |
23 ms |
1912 KB |
correct |
42 |
Correct |
23 ms |
1888 KB |
correct |
43 |
Correct |
10 ms |
1236 KB |
correct |
44 |
Correct |
9 ms |
980 KB |
correct |
45 |
Correct |
10 ms |
1056 KB |
correct |
46 |
Correct |
9 ms |
980 KB |
correct |
47 |
Correct |
6 ms |
668 KB |
correct |
48 |
Correct |
2 ms |
340 KB |
correct |
49 |
Correct |
4 ms |
468 KB |
correct |
50 |
Correct |
6 ms |
596 KB |
correct |
51 |
Correct |
12 ms |
1132 KB |
correct |
52 |
Correct |
9 ms |
956 KB |
correct |
53 |
Correct |
8 ms |
980 KB |
correct |
54 |
Correct |
11 ms |
1232 KB |
correct |
55 |
Correct |
11 ms |
1132 KB |
correct |
56 |
Correct |
11 ms |
1108 KB |
correct |
57 |
Correct |
11 ms |
1056 KB |
correct |
58 |
Correct |
1 ms |
340 KB |
correct |
59 |
Correct |
1 ms |
340 KB |
correct |
60 |
Correct |
79 ms |
4816 KB |
correct |
61 |
Correct |
135 ms |
6764 KB |
correct |
62 |
Correct |
151 ms |
6868 KB |
correct |
63 |
Correct |
131 ms |
6772 KB |
correct |
64 |
Correct |
129 ms |
6768 KB |
correct |
65 |
Correct |
129 ms |
6732 KB |
correct |
66 |
Correct |
141 ms |
6704 KB |
correct |
67 |
Correct |
134 ms |
6716 KB |
correct |
68 |
Correct |
132 ms |
6628 KB |
correct |
69 |
Correct |
135 ms |
6664 KB |
correct |
70 |
Correct |
0 ms |
340 KB |
correct |
71 |
Correct |
132 ms |
6708 KB |
correct |
72 |
Correct |
139 ms |
6748 KB |
correct |
73 |
Correct |
0 ms |
340 KB |
correct |
74 |
Correct |
134 ms |
6772 KB |
correct |
75 |
Correct |
135 ms |
6584 KB |
correct |
76 |
Correct |
59 ms |
2724 KB |
correct |
77 |
Correct |
135 ms |
6768 KB |
correct |
78 |
Correct |
136 ms |
6704 KB |
correct |
79 |
Correct |
134 ms |
6696 KB |
correct |
80 |
Correct |
134 ms |
6536 KB |
correct |
81 |
Correct |
117 ms |
6092 KB |
correct |
82 |
Correct |
133 ms |
6572 KB |
correct |
83 |
Correct |
89 ms |
3832 KB |
correct |
84 |
Correct |
59 ms |
4440 KB |
correct |
85 |
Correct |
52 ms |
4048 KB |
correct |
86 |
Correct |
39 ms |
2816 KB |
correct |
87 |
Correct |
32 ms |
2260 KB |
correct |
88 |
Correct |
27 ms |
1748 KB |
correct |
89 |
Correct |
38 ms |
1696 KB |
correct |
90 |
Correct |
25 ms |
1592 KB |
correct |
91 |
Correct |
16 ms |
552 KB |
correct |
92 |
Correct |
9 ms |
340 KB |
correct |
93 |
Correct |
49 ms |
4160 KB |
correct |
94 |
Correct |
40 ms |
2764 KB |
correct |
95 |
Correct |
41 ms |
2892 KB |
correct |
96 |
Correct |
27 ms |
1652 KB |
correct |
97 |
Correct |
36 ms |
1680 KB |
correct |
98 |
Correct |
31 ms |
2236 KB |
correct |
99 |
Correct |
29 ms |
1760 KB |
correct |
100 |
Correct |
17 ms |
772 KB |
correct |
101 |
Correct |
14 ms |
468 KB |
correct |
102 |
Correct |
58 ms |
3408 KB |
correct |
103 |
Correct |
66 ms |
3416 KB |
correct |
104 |
Correct |
57 ms |
3380 KB |
correct |
105 |
Correct |
58 ms |
3396 KB |
correct |