# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
964813 |
2024-04-17T15:29:51 Z |
AdamGS |
Simurgh (IOI17_simurgh) |
C++17 |
|
288 ms |
8692 KB |
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=507;
vector<pair<int,int>>V[LIM];
vector<int>D;
pair<int,int>kraw[LIM*LIM];
int pre[LIM], mi[LIM], oc[LIM], jaki[LIM], drzewo[LIM*LIM], typ[LIM*LIM], F[LIM], lpre, n, m;
int fnd(int x) {
if(F[x]==x) return x;
return F[x]=fnd(F[x]);
}
bool uni(int a, int b) {
if(fnd(a)==fnd(b)) return false;
F[fnd(a)]=fnd(b);
return true;
}
void DFS(int x, int o) {
pre[x]=mi[x]=++lpre;
for(auto i : V[x]) if(i.st!=o) {
if(!pre[i.st]) {
oc[i.st]=x;
jaki[i.st]=i.nd;
drzewo[i.nd]=1;
DFS(i.st, x);
mi[x]=min(mi[x], mi[i.st]);
} else mi[x]=min(mi[x], pre[i.st]);
}
if(x && mi[x]==pre[x]) typ[jaki[x]]=1;
}
int cnt(vector<int>P) {
rep(i, n) F[i]=i;
for(auto i : P) uni(kraw[i].st, kraw[i].nd);
int sum=0;
for(auto i : D) if(uni(kraw[i].st, kraw[i].nd)) {
sum+=typ[i];
P.pb(i);
}
return count_common_roads(P)-sum;
}
void solve(vector<int>P, int k) {
if(!k) {
for(auto i : P) typ[i]=0;
return;
}
if(P.size()==k) {
for(auto i : P) typ[i]=1;
return;
}
int sr=(P.size()+1)/2;
vector<int>A, B;
rep(i, sr) A.pb(P[i]);
for(int i=sr; i<P.size(); ++i) B.pb(P[i]);
int x=cnt(A);
solve(A, x);
solve(B, k-x);
}
vector<int>find_roads(int _n, vector<int>_u, vector<int>_v) {
n=_n; m=_u.size();
rep(i, m) {
kraw[i]={_u[i], _v[i]};
if(kraw[i].st>kraw[i].nd) swap(kraw[i].st, kraw[i].nd);
V[kraw[i].st].pb({kraw[i].nd, i});
V[kraw[i].nd].pb({kraw[i].st, i});
typ[i]=-1;
}
DFS(0, 0);
rep(i, m) if(drzewo[i]) D.pb(i);
int x=count_common_roads(D);
rep(i, m) if(!drzewo[i]) {
int a=kraw[i].st, b=kraw[i].nd;
if(pre[a]<pre[b]) swap(a, b);
bool ok=false;
for(int j=a; j!=b; j=oc[j]) {
if(typ[jaki[j]]==-1) ok=true;
}
if(!ok) continue;
for(int j=a; j!=b; j=oc[j]) if(typ[jaki[j]]==-1) {
vector<int>T=D;
rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
int y=count_common_roads(T);
if(x==y) typ[jaki[j]]=typ[i];
else if(x==y+1) {
typ[jaki[j]]=1;
typ[i]=0;
} else {
typ[jaki[j]]=0;
typ[i]=1;
}
}
if(typ[i]==-1) {
ok=false;
for(int j=a; j!=b; j=oc[j]) if(typ[jaki[j]]!=-1) {
vector<int>T=D;
rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
int y=count_common_roads(T);
typ[i]=y-x+typ[jaki[j]];
ok=true;
break;
}
if(!ok) typ[i]=0;
}
for(int j=a; j!=b; j=oc[j]) if(typ[jaki[j]]==-1) typ[jaki[j]]=typ[i];
}
rep(i, n) {
vector<int>P;
rep(j, m) if(kraw[j].st==i || kraw[j].nd==i) P.pb(j);
solve(P, cnt(P));
}
vector<int>ans;
rep(i, m) if(typ[i]==1) ans.pb(i);
return ans;
}
Compilation message
simurgh.cpp: In function 'void solve(std::vector<int>, int)':
simurgh.cpp:51:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
51 | if(P.size()==k) {
| ~~~~~~~~^~~
simurgh.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=sr; i<P.size(); ++i) B.pb(P[i]);
| ~^~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
simurgh.cpp:85:7: note: in expansion of macro 'rep'
85 | rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
| ^~~
simurgh.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
simurgh.cpp:100:9: note: in expansion of macro 'rep'
100 | rep(l, T.size()) if(T[l]==jaki[j]) T[l]=i;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
correct |
2 |
Correct |
1 ms |
2396 KB |
correct |
3 |
Correct |
1 ms |
2396 KB |
correct |
4 |
Correct |
1 ms |
2396 KB |
correct |
5 |
Correct |
1 ms |
2504 KB |
correct |
6 |
Correct |
1 ms |
2396 KB |
correct |
7 |
Correct |
1 ms |
2396 KB |
correct |
8 |
Correct |
1 ms |
2392 KB |
correct |
9 |
Correct |
1 ms |
2396 KB |
correct |
10 |
Correct |
1 ms |
2396 KB |
correct |
11 |
Correct |
1 ms |
2396 KB |
correct |
12 |
Correct |
1 ms |
2396 KB |
correct |
13 |
Correct |
1 ms |
2648 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
correct |
2 |
Correct |
1 ms |
2396 KB |
correct |
3 |
Correct |
1 ms |
2396 KB |
correct |
4 |
Correct |
1 ms |
2396 KB |
correct |
5 |
Correct |
1 ms |
2504 KB |
correct |
6 |
Correct |
1 ms |
2396 KB |
correct |
7 |
Correct |
1 ms |
2396 KB |
correct |
8 |
Correct |
1 ms |
2392 KB |
correct |
9 |
Correct |
1 ms |
2396 KB |
correct |
10 |
Correct |
1 ms |
2396 KB |
correct |
11 |
Correct |
1 ms |
2396 KB |
correct |
12 |
Correct |
1 ms |
2396 KB |
correct |
13 |
Correct |
1 ms |
2648 KB |
correct |
14 |
Correct |
2 ms |
2392 KB |
correct |
15 |
Correct |
2 ms |
2396 KB |
correct |
16 |
Correct |
2 ms |
2396 KB |
correct |
17 |
Correct |
3 ms |
2652 KB |
correct |
18 |
Correct |
1 ms |
2396 KB |
correct |
19 |
Correct |
2 ms |
2396 KB |
correct |
20 |
Correct |
2 ms |
2396 KB |
correct |
21 |
Correct |
2 ms |
2396 KB |
correct |
22 |
Correct |
2 ms |
2556 KB |
correct |
23 |
Correct |
1 ms |
2396 KB |
correct |
24 |
Correct |
1 ms |
2396 KB |
correct |
25 |
Correct |
1 ms |
2396 KB |
correct |
26 |
Correct |
2 ms |
2396 KB |
correct |
27 |
Correct |
1 ms |
2396 KB |
correct |
28 |
Correct |
1 ms |
2396 KB |
correct |
29 |
Correct |
1 ms |
2396 KB |
correct |
30 |
Correct |
2 ms |
2544 KB |
correct |
31 |
Correct |
2 ms |
2396 KB |
correct |
32 |
Correct |
2 ms |
2396 KB |
correct |
33 |
Correct |
1 ms |
2396 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
correct |
2 |
Correct |
1 ms |
2396 KB |
correct |
3 |
Correct |
1 ms |
2396 KB |
correct |
4 |
Correct |
1 ms |
2396 KB |
correct |
5 |
Correct |
1 ms |
2504 KB |
correct |
6 |
Correct |
1 ms |
2396 KB |
correct |
7 |
Correct |
1 ms |
2396 KB |
correct |
8 |
Correct |
1 ms |
2392 KB |
correct |
9 |
Correct |
1 ms |
2396 KB |
correct |
10 |
Correct |
1 ms |
2396 KB |
correct |
11 |
Correct |
1 ms |
2396 KB |
correct |
12 |
Correct |
1 ms |
2396 KB |
correct |
13 |
Correct |
1 ms |
2648 KB |
correct |
14 |
Correct |
2 ms |
2392 KB |
correct |
15 |
Correct |
2 ms |
2396 KB |
correct |
16 |
Correct |
2 ms |
2396 KB |
correct |
17 |
Correct |
3 ms |
2652 KB |
correct |
18 |
Correct |
1 ms |
2396 KB |
correct |
19 |
Correct |
2 ms |
2396 KB |
correct |
20 |
Correct |
2 ms |
2396 KB |
correct |
21 |
Correct |
2 ms |
2396 KB |
correct |
22 |
Correct |
2 ms |
2556 KB |
correct |
23 |
Correct |
1 ms |
2396 KB |
correct |
24 |
Correct |
1 ms |
2396 KB |
correct |
25 |
Correct |
1 ms |
2396 KB |
correct |
26 |
Correct |
2 ms |
2396 KB |
correct |
27 |
Correct |
1 ms |
2396 KB |
correct |
28 |
Correct |
1 ms |
2396 KB |
correct |
29 |
Correct |
1 ms |
2396 KB |
correct |
30 |
Correct |
2 ms |
2544 KB |
correct |
31 |
Correct |
2 ms |
2396 KB |
correct |
32 |
Correct |
2 ms |
2396 KB |
correct |
33 |
Correct |
1 ms |
2396 KB |
correct |
34 |
Correct |
49 ms |
3888 KB |
correct |
35 |
Correct |
46 ms |
3840 KB |
correct |
36 |
Correct |
39 ms |
3672 KB |
correct |
37 |
Correct |
9 ms |
2396 KB |
correct |
38 |
Correct |
53 ms |
3876 KB |
correct |
39 |
Correct |
40 ms |
3672 KB |
correct |
40 |
Correct |
35 ms |
3420 KB |
correct |
41 |
Correct |
37 ms |
3676 KB |
correct |
42 |
Correct |
37 ms |
3676 KB |
correct |
43 |
Correct |
23 ms |
3412 KB |
correct |
44 |
Correct |
20 ms |
2908 KB |
correct |
45 |
Correct |
22 ms |
3160 KB |
correct |
46 |
Correct |
21 ms |
3064 KB |
correct |
47 |
Correct |
13 ms |
2652 KB |
correct |
48 |
Correct |
5 ms |
2396 KB |
correct |
49 |
Correct |
7 ms |
2396 KB |
correct |
50 |
Correct |
13 ms |
2804 KB |
correct |
51 |
Correct |
21 ms |
3164 KB |
correct |
52 |
Correct |
20 ms |
2908 KB |
correct |
53 |
Correct |
20 ms |
3068 KB |
correct |
54 |
Correct |
26 ms |
3160 KB |
correct |
55 |
Correct |
26 ms |
3412 KB |
correct |
56 |
Correct |
26 ms |
3204 KB |
correct |
57 |
Correct |
28 ms |
3188 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
correct |
2 |
Correct |
1 ms |
2648 KB |
correct |
3 |
Correct |
167 ms |
6780 KB |
correct |
4 |
Correct |
274 ms |
8644 KB |
correct |
5 |
Correct |
283 ms |
8664 KB |
correct |
6 |
Correct |
232 ms |
8660 KB |
correct |
7 |
Correct |
235 ms |
8640 KB |
correct |
8 |
Correct |
225 ms |
8644 KB |
correct |
9 |
Correct |
264 ms |
8536 KB |
correct |
10 |
Correct |
288 ms |
8680 KB |
correct |
11 |
Correct |
264 ms |
8648 KB |
correct |
12 |
Correct |
277 ms |
8664 KB |
correct |
13 |
Correct |
1 ms |
2396 KB |
correct |
14 |
Correct |
242 ms |
8692 KB |
correct |
15 |
Correct |
288 ms |
8396 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
correct |
2 |
Correct |
1 ms |
2396 KB |
correct |
3 |
Correct |
1 ms |
2396 KB |
correct |
4 |
Correct |
1 ms |
2396 KB |
correct |
5 |
Correct |
1 ms |
2504 KB |
correct |
6 |
Correct |
1 ms |
2396 KB |
correct |
7 |
Correct |
1 ms |
2396 KB |
correct |
8 |
Correct |
1 ms |
2392 KB |
correct |
9 |
Correct |
1 ms |
2396 KB |
correct |
10 |
Correct |
1 ms |
2396 KB |
correct |
11 |
Correct |
1 ms |
2396 KB |
correct |
12 |
Correct |
1 ms |
2396 KB |
correct |
13 |
Correct |
1 ms |
2648 KB |
correct |
14 |
Correct |
2 ms |
2392 KB |
correct |
15 |
Correct |
2 ms |
2396 KB |
correct |
16 |
Correct |
2 ms |
2396 KB |
correct |
17 |
Correct |
3 ms |
2652 KB |
correct |
18 |
Correct |
1 ms |
2396 KB |
correct |
19 |
Correct |
2 ms |
2396 KB |
correct |
20 |
Correct |
2 ms |
2396 KB |
correct |
21 |
Correct |
2 ms |
2396 KB |
correct |
22 |
Correct |
2 ms |
2556 KB |
correct |
23 |
Correct |
1 ms |
2396 KB |
correct |
24 |
Correct |
1 ms |
2396 KB |
correct |
25 |
Correct |
1 ms |
2396 KB |
correct |
26 |
Correct |
2 ms |
2396 KB |
correct |
27 |
Correct |
1 ms |
2396 KB |
correct |
28 |
Correct |
1 ms |
2396 KB |
correct |
29 |
Correct |
1 ms |
2396 KB |
correct |
30 |
Correct |
2 ms |
2544 KB |
correct |
31 |
Correct |
2 ms |
2396 KB |
correct |
32 |
Correct |
2 ms |
2396 KB |
correct |
33 |
Correct |
1 ms |
2396 KB |
correct |
34 |
Correct |
49 ms |
3888 KB |
correct |
35 |
Correct |
46 ms |
3840 KB |
correct |
36 |
Correct |
39 ms |
3672 KB |
correct |
37 |
Correct |
9 ms |
2396 KB |
correct |
38 |
Correct |
53 ms |
3876 KB |
correct |
39 |
Correct |
40 ms |
3672 KB |
correct |
40 |
Correct |
35 ms |
3420 KB |
correct |
41 |
Correct |
37 ms |
3676 KB |
correct |
42 |
Correct |
37 ms |
3676 KB |
correct |
43 |
Correct |
23 ms |
3412 KB |
correct |
44 |
Correct |
20 ms |
2908 KB |
correct |
45 |
Correct |
22 ms |
3160 KB |
correct |
46 |
Correct |
21 ms |
3064 KB |
correct |
47 |
Correct |
13 ms |
2652 KB |
correct |
48 |
Correct |
5 ms |
2396 KB |
correct |
49 |
Correct |
7 ms |
2396 KB |
correct |
50 |
Correct |
13 ms |
2804 KB |
correct |
51 |
Correct |
21 ms |
3164 KB |
correct |
52 |
Correct |
20 ms |
2908 KB |
correct |
53 |
Correct |
20 ms |
3068 KB |
correct |
54 |
Correct |
26 ms |
3160 KB |
correct |
55 |
Correct |
26 ms |
3412 KB |
correct |
56 |
Correct |
26 ms |
3204 KB |
correct |
57 |
Correct |
28 ms |
3188 KB |
correct |
58 |
Correct |
1 ms |
2396 KB |
correct |
59 |
Correct |
1 ms |
2648 KB |
correct |
60 |
Correct |
167 ms |
6780 KB |
correct |
61 |
Correct |
274 ms |
8644 KB |
correct |
62 |
Correct |
283 ms |
8664 KB |
correct |
63 |
Correct |
232 ms |
8660 KB |
correct |
64 |
Correct |
235 ms |
8640 KB |
correct |
65 |
Correct |
225 ms |
8644 KB |
correct |
66 |
Correct |
264 ms |
8536 KB |
correct |
67 |
Correct |
288 ms |
8680 KB |
correct |
68 |
Correct |
264 ms |
8648 KB |
correct |
69 |
Correct |
277 ms |
8664 KB |
correct |
70 |
Correct |
1 ms |
2396 KB |
correct |
71 |
Correct |
242 ms |
8692 KB |
correct |
72 |
Correct |
288 ms |
8396 KB |
correct |
73 |
Correct |
1 ms |
2396 KB |
correct |
74 |
Incorrect |
265 ms |
8644 KB |
WA in grader: NO |
75 |
Halted |
0 ms |
0 KB |
- |