# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
424573 |
2021-06-12T06:27:27 Z |
Pyqe |
Simurgh (IOI17_simurgh) |
C++14 |
|
254 ms |
8308 KB |
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
#define mp make_pair
#define fr first
#define sc second
long long n,m,nn=0,nm,dsu[569],ex[569],pr[569],dh[569],sr[569],sq[569],zs=0;
pair<long long,long long> ed[125069],ca[569];
bitset<125069> spc;
vector<pair<long long,long long>> al[569];
bitset<569> vtd,kd,ve;
long long fd(long long x)
{
if(dsu[x]!=x)
{
dsu[x]=fd(dsu[x]);
}
return dsu[x];
}
void bd(long long x)
{
long long i,sz=al[x].size(),l,p;
vtd[x]=1;
for(i=0;i<sz;i++)
{
l=al[x][i].fr;
p=al[x][i].sc;
if(!vtd[l])
{
pr[l]=x;
dh[l]=dh[x]+1;
sr[l]=p;
bd(l);
}
}
}
long long qr(long long x,long long w)
{
long long i,sz=al[x].size(),k,l,p,c=0;
vector<int> v;
for(i=1;i<=n;i++)
{
dsu[i]=i;
}
for(i=0;i<sz;i++)
{
l=al[x][i].fr;
p=al[x][i].sc;
if(i<=w&&!vtd[i])
{
v.push_back(p-1);
dsu[fd(l)]=fd(x);
}
}
for(i=1;i<=nn;i++)
{
p=ex[i];
k=ed[p].fr;
l=ed[p].sc;
if(fd(k)!=fd(l))
{
dsu[fd(l)]=fd(k);
v.push_back(p-1);
c+=kd[i];
}
}
return count_common_roads(v)-c;
}
vector<int> find_roads(int on,vector<int> ka,vector<int> la)
{
long long i,j,k,l,sz,c,mx,lh,rh,md,zz;
bool bad;
vector<int> v;
n=on;
m=ka.size();
for(i=1;i<=n;i++)
{
dsu[i]=i;
}
for(i=1;i<=m;i++)
{
k=ka[i-1]+1;
l=la[i-1]+1;
ed[i]={k,l};
if(fd(k)!=fd(l))
{
dsu[fd(l)]=fd(k);
nn++;
ex[nn]=i;
spc[i]=1;
al[k].push_back({l,nn});
al[l].push_back({k,nn});
v.push_back(i-1);
kd[nn]=1;
}
}
bd(1);
c=count_common_roads(v);
for(i=1;i<=n;i++)
{
dsu[i]=i;
al[i].clear();
}
for(i=1;i<=m;i++)
{
k=ed[i].fr;
l=ed[i].sc;
al[k].push_back({l,i});
if(!spc[i]&&fd(k)!=fd(l))
{
nm=0;
mx=c;
bad=0;
for(;k!=l;k=pr[k])
{
if(dh[k]<dh[l])
{
swap(k,l);
}
if(!ve[sr[k]]||(!kd[sr[k]]&&!bad))
{
v.clear();
for(j=1;j<=nn;j++)
{
if(j!=sr[k])
{
v.push_back(ex[j]-1);
}
}
v.push_back(i-1);
nm++;
ca[nm]={count_common_roads(v),sr[k]};
mx=max(mx,ca[nm].fr);
bad|=ve[sr[k]];
ve[sr[k]]=1;
}
dsu[fd(l)]=fd(k);
}
for(j=1;j<=nm;j++)
{
k=ca[j].fr;
l=ca[j].sc;
kd[l]=k<mx;
}
}
}
for(i=1;i<=n;i++)
{
vtd.reset();
sz=al[i].size();
for(;qr(i,sz-1);)
{
for(zz=sz-1,lh=0,rh=sz-2;lh<=rh;)
{
md=(lh+rh)/2;
if(qr(i,md))
{
zz=md;
rh=md-1;
}
else
{
lh=md+1;
}
}
zs++;
sq[zs]=al[i][zz].sc;
vtd[zz]=1;
}
}
v.clear();
for(i=1;i<=zs;i++)
{
v.push_back(sq[i]-1);
}
return v;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
1 ms |
312 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 |
0 ms |
332 KB |
correct |
9 |
Correct |
1 ms |
312 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
1 ms |
312 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 |
0 ms |
332 KB |
correct |
9 |
Correct |
1 ms |
312 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 |
2 ms |
332 KB |
correct |
15 |
Correct |
2 ms |
332 KB |
correct |
16 |
Correct |
2 ms |
332 KB |
correct |
17 |
Correct |
2 ms |
312 KB |
correct |
18 |
Correct |
1 ms |
332 KB |
correct |
19 |
Correct |
2 ms |
332 KB |
correct |
20 |
Correct |
2 ms |
332 KB |
correct |
21 |
Correct |
2 ms |
332 KB |
correct |
22 |
Correct |
2 ms |
320 KB |
correct |
23 |
Correct |
2 ms |
332 KB |
correct |
24 |
Correct |
1 ms |
332 KB |
correct |
25 |
Correct |
1 ms |
316 KB |
correct |
26 |
Correct |
2 ms |
376 KB |
correct |
27 |
Correct |
2 ms |
460 KB |
correct |
28 |
Correct |
1 ms |
332 KB |
correct |
29 |
Correct |
2 ms |
312 KB |
correct |
30 |
Correct |
2 ms |
332 KB |
correct |
31 |
Correct |
2 ms |
332 KB |
correct |
32 |
Correct |
2 ms |
332 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
1 ms |
312 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 |
0 ms |
332 KB |
correct |
9 |
Correct |
1 ms |
312 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 |
2 ms |
332 KB |
correct |
15 |
Correct |
2 ms |
332 KB |
correct |
16 |
Correct |
2 ms |
332 KB |
correct |
17 |
Correct |
2 ms |
312 KB |
correct |
18 |
Correct |
1 ms |
332 KB |
correct |
19 |
Correct |
2 ms |
332 KB |
correct |
20 |
Correct |
2 ms |
332 KB |
correct |
21 |
Correct |
2 ms |
332 KB |
correct |
22 |
Correct |
2 ms |
320 KB |
correct |
23 |
Correct |
2 ms |
332 KB |
correct |
24 |
Correct |
1 ms |
332 KB |
correct |
25 |
Correct |
1 ms |
316 KB |
correct |
26 |
Correct |
2 ms |
376 KB |
correct |
27 |
Correct |
2 ms |
460 KB |
correct |
28 |
Correct |
1 ms |
332 KB |
correct |
29 |
Correct |
2 ms |
312 KB |
correct |
30 |
Correct |
2 ms |
332 KB |
correct |
31 |
Correct |
2 ms |
332 KB |
correct |
32 |
Correct |
2 ms |
332 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
34 |
Correct |
45 ms |
1996 KB |
correct |
35 |
Correct |
49 ms |
1936 KB |
correct |
36 |
Correct |
39 ms |
1612 KB |
correct |
37 |
Correct |
16 ms |
332 KB |
correct |
38 |
Correct |
47 ms |
2084 KB |
correct |
39 |
Correct |
44 ms |
1848 KB |
correct |
40 |
Correct |
39 ms |
1612 KB |
correct |
41 |
Correct |
49 ms |
2100 KB |
correct |
42 |
Correct |
41 ms |
2096 KB |
correct |
43 |
Correct |
29 ms |
1404 KB |
correct |
44 |
Correct |
27 ms |
1100 KB |
correct |
45 |
Correct |
31 ms |
1164 KB |
correct |
46 |
Correct |
26 ms |
972 KB |
correct |
47 |
Correct |
19 ms |
656 KB |
correct |
48 |
Correct |
8 ms |
332 KB |
correct |
49 |
Correct |
12 ms |
332 KB |
correct |
50 |
Correct |
19 ms |
588 KB |
correct |
51 |
Correct |
31 ms |
1228 KB |
correct |
52 |
Correct |
27 ms |
1100 KB |
correct |
53 |
Correct |
26 ms |
972 KB |
correct |
54 |
Correct |
30 ms |
1344 KB |
correct |
55 |
Correct |
28 ms |
1264 KB |
correct |
56 |
Correct |
28 ms |
1228 KB |
correct |
57 |
Correct |
28 ms |
1228 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
133 ms |
5228 KB |
correct |
4 |
Correct |
221 ms |
8184 KB |
correct |
5 |
Correct |
254 ms |
8216 KB |
correct |
6 |
Correct |
197 ms |
8188 KB |
correct |
7 |
Correct |
194 ms |
8184 KB |
correct |
8 |
Correct |
197 ms |
8168 KB |
correct |
9 |
Correct |
220 ms |
8132 KB |
correct |
10 |
Correct |
213 ms |
8188 KB |
correct |
11 |
Correct |
219 ms |
8260 KB |
correct |
12 |
Correct |
220 ms |
8184 KB |
correct |
13 |
Correct |
1 ms |
332 KB |
correct |
14 |
Correct |
217 ms |
8184 KB |
correct |
15 |
Correct |
220 ms |
8308 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
correct |
2 |
Correct |
1 ms |
332 KB |
correct |
3 |
Correct |
1 ms |
312 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 |
0 ms |
332 KB |
correct |
9 |
Correct |
1 ms |
312 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 |
2 ms |
332 KB |
correct |
15 |
Correct |
2 ms |
332 KB |
correct |
16 |
Correct |
2 ms |
332 KB |
correct |
17 |
Correct |
2 ms |
312 KB |
correct |
18 |
Correct |
1 ms |
332 KB |
correct |
19 |
Correct |
2 ms |
332 KB |
correct |
20 |
Correct |
2 ms |
332 KB |
correct |
21 |
Correct |
2 ms |
332 KB |
correct |
22 |
Correct |
2 ms |
320 KB |
correct |
23 |
Correct |
2 ms |
332 KB |
correct |
24 |
Correct |
1 ms |
332 KB |
correct |
25 |
Correct |
1 ms |
316 KB |
correct |
26 |
Correct |
2 ms |
376 KB |
correct |
27 |
Correct |
2 ms |
460 KB |
correct |
28 |
Correct |
1 ms |
332 KB |
correct |
29 |
Correct |
2 ms |
312 KB |
correct |
30 |
Correct |
2 ms |
332 KB |
correct |
31 |
Correct |
2 ms |
332 KB |
correct |
32 |
Correct |
2 ms |
332 KB |
correct |
33 |
Correct |
2 ms |
332 KB |
correct |
34 |
Correct |
45 ms |
1996 KB |
correct |
35 |
Correct |
49 ms |
1936 KB |
correct |
36 |
Correct |
39 ms |
1612 KB |
correct |
37 |
Correct |
16 ms |
332 KB |
correct |
38 |
Correct |
47 ms |
2084 KB |
correct |
39 |
Correct |
44 ms |
1848 KB |
correct |
40 |
Correct |
39 ms |
1612 KB |
correct |
41 |
Correct |
49 ms |
2100 KB |
correct |
42 |
Correct |
41 ms |
2096 KB |
correct |
43 |
Correct |
29 ms |
1404 KB |
correct |
44 |
Correct |
27 ms |
1100 KB |
correct |
45 |
Correct |
31 ms |
1164 KB |
correct |
46 |
Correct |
26 ms |
972 KB |
correct |
47 |
Correct |
19 ms |
656 KB |
correct |
48 |
Correct |
8 ms |
332 KB |
correct |
49 |
Correct |
12 ms |
332 KB |
correct |
50 |
Correct |
19 ms |
588 KB |
correct |
51 |
Correct |
31 ms |
1228 KB |
correct |
52 |
Correct |
27 ms |
1100 KB |
correct |
53 |
Correct |
26 ms |
972 KB |
correct |
54 |
Correct |
30 ms |
1344 KB |
correct |
55 |
Correct |
28 ms |
1264 KB |
correct |
56 |
Correct |
28 ms |
1228 KB |
correct |
57 |
Correct |
28 ms |
1228 KB |
correct |
58 |
Correct |
1 ms |
332 KB |
correct |
59 |
Correct |
1 ms |
332 KB |
correct |
60 |
Correct |
133 ms |
5228 KB |
correct |
61 |
Correct |
221 ms |
8184 KB |
correct |
62 |
Correct |
254 ms |
8216 KB |
correct |
63 |
Correct |
197 ms |
8188 KB |
correct |
64 |
Correct |
194 ms |
8184 KB |
correct |
65 |
Correct |
197 ms |
8168 KB |
correct |
66 |
Correct |
220 ms |
8132 KB |
correct |
67 |
Correct |
213 ms |
8188 KB |
correct |
68 |
Correct |
219 ms |
8260 KB |
correct |
69 |
Correct |
220 ms |
8184 KB |
correct |
70 |
Correct |
1 ms |
332 KB |
correct |
71 |
Correct |
217 ms |
8184 KB |
correct |
72 |
Correct |
220 ms |
8308 KB |
correct |
73 |
Correct |
1 ms |
332 KB |
correct |
74 |
Correct |
239 ms |
8232 KB |
correct |
75 |
Correct |
217 ms |
7620 KB |
correct |
76 |
Correct |
120 ms |
2996 KB |
correct |
77 |
Correct |
216 ms |
8132 KB |
correct |
78 |
Correct |
224 ms |
8116 KB |
correct |
79 |
Correct |
217 ms |
8004 KB |
correct |
80 |
Correct |
217 ms |
7504 KB |
correct |
81 |
Correct |
195 ms |
6464 KB |
correct |
82 |
Correct |
218 ms |
7396 KB |
correct |
83 |
Correct |
195 ms |
4292 KB |
correct |
84 |
Correct |
152 ms |
4892 KB |
correct |
85 |
Correct |
151 ms |
4720 KB |
correct |
86 |
Correct |
123 ms |
3156 KB |
correct |
87 |
Correct |
112 ms |
2380 KB |
correct |
88 |
Correct |
110 ms |
1988 KB |
correct |
89 |
Correct |
96 ms |
1796 KB |
correct |
90 |
Correct |
90 ms |
1612 KB |
correct |
91 |
Correct |
43 ms |
496 KB |
correct |
92 |
Correct |
33 ms |
332 KB |
correct |
93 |
Correct |
162 ms |
4716 KB |
correct |
94 |
Correct |
127 ms |
3164 KB |
correct |
95 |
Correct |
126 ms |
3052 KB |
correct |
96 |
Correct |
96 ms |
1740 KB |
correct |
97 |
Correct |
98 ms |
1868 KB |
correct |
98 |
Correct |
114 ms |
2492 KB |
correct |
99 |
Correct |
101 ms |
1848 KB |
correct |
100 |
Correct |
59 ms |
716 KB |
correct |
101 |
Correct |
32 ms |
332 KB |
correct |
102 |
Correct |
133 ms |
4444 KB |
correct |
103 |
Correct |
138 ms |
4300 KB |
correct |
104 |
Correct |
135 ms |
4344 KB |
correct |
105 |
Correct |
132 ms |
4348 KB |
correct |