# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
302688 |
2020-09-19T04:04:53 Z |
kevlee |
Simurgh (IOI17_simurgh) |
C++17 |
|
304 ms |
7032 KB |
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
vi ans;
int m;
vp edges[505];
vi nodes[505];
int group[505];
bool used[505];
int asked[50005];
int f(int x) {
return x == group[x] ? x : group[x] = f(group[x]);
}
vi find_roads(int n, vi u, vi v) {
m = u.size();
FOR(i, 0, m-1) {
edges[u[i]].emplace_back(v[i], i);
edges[v[i]].emplace_back(u[i], i);
}
FOR(i, 0, n-1) {
int sz = edges[i].size();
if (sz == 1) {
ans.pb(edges[i][0].se);
continue;
}
FOR(j, 0, n-1) group[j] = j;
vi query;
FOR(j, 0, m-1) {
if (u[j] == i || v[j] == i) continue;
int x = f(u[j]);
int y = f(v[j]);
if (x != y) {
query.pb(j);
group[x] = y;
}
}
FOR(j, 0, n-1) nodes[j].clear();
FOR(j, 0, edges[i].size() - 1) {
nodes[f(edges[i][j].fi)].pb(edges[i][j].fi);
}
FOR(k, 0, n-1) {
//cout << i <<" "<<k << " " << nodes[k].size() << endl;
if (nodes[k].size() == 0 || k == i) continue;
vp res;
vi ask = query;
FOR(j, 0, n-1) used[j] = false;
used[k] = used[i] = true;
vi candidate;
FOR(j, 0, edges[i].size() - 1) {
int x = f(edges[i][j].fi);
if (!used[x]) {
used[x] = true;
ask.pb(edges[i][j].se);
} else if (x == k) {
candidate.pb(edges[i][j].se);
}
}
bool fir = true;
for (auto it: candidate) {
if (asked[it]) {
if (asked[it] == 2 && fir) {
fir = false;
goto there;
}
continue;
}
there:;
ask.pb(it);
asked[it] = 1;
//for (auto q: ask) cout << q <<' ';
//cout << endl;
int cnt = count_common_roads(ask);
res.pb({cnt, it});
ask.pop_back();
}
sort(res.rbegin(), res.rend());
for (auto p: res) {
if (p.fi != res[0].fi) {
break;
}
ans.pb(p.se);
asked[p.se] = 2;
}
}
}
sort(all(ans));
auto iter = unique(all(ans));
ans.resize(distance(ans.begin(), iter));
//cout << ans.size() << endl;
//for (auto it: ans) cout << it << ' ' ;
//cout << endl;
return ans;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:23:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | #define FOR(i, a, b) for (int i = (a); i <= (b); i++)
| ^
simurgh.cpp:59:5: note: in expansion of macro 'FOR'
59 | FOR(j, 0, edges[i].size() - 1) {
| ^~~
simurgh.cpp:23:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | #define FOR(i, a, b) for (int i = (a); i <= (b); i++)
| ^
simurgh.cpp:70:7: note: in expansion of macro 'FOR'
70 | FOR(j, 0, edges[i].size() - 1) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
1 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
512 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
1 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
512 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
360 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
2 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
4 ms |
384 KB |
correct |
21 |
Correct |
3 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
1 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
512 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
360 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
2 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
4 ms |
384 KB |
correct |
21 |
Correct |
3 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
34 |
Correct |
302 ms |
1408 KB |
correct |
35 |
Correct |
290 ms |
1784 KB |
correct |
36 |
Correct |
201 ms |
1408 KB |
correct |
37 |
Correct |
18 ms |
384 KB |
correct |
38 |
Correct |
296 ms |
1692 KB |
correct |
39 |
Correct |
264 ms |
1536 KB |
correct |
40 |
Correct |
197 ms |
1408 KB |
correct |
41 |
Correct |
300 ms |
1664 KB |
correct |
42 |
Correct |
304 ms |
1692 KB |
correct |
43 |
Correct |
155 ms |
1272 KB |
correct |
44 |
Correct |
127 ms |
896 KB |
correct |
45 |
Correct |
150 ms |
1024 KB |
correct |
46 |
Correct |
118 ms |
1016 KB |
correct |
47 |
Correct |
51 ms |
640 KB |
correct |
48 |
Correct |
7 ms |
384 KB |
correct |
49 |
Correct |
17 ms |
384 KB |
correct |
50 |
Correct |
51 ms |
640 KB |
correct |
51 |
Correct |
153 ms |
1024 KB |
correct |
52 |
Correct |
129 ms |
1016 KB |
correct |
53 |
Correct |
116 ms |
896 KB |
correct |
54 |
Correct |
155 ms |
1272 KB |
correct |
55 |
Correct |
135 ms |
1172 KB |
correct |
56 |
Correct |
134 ms |
1024 KB |
correct |
57 |
Correct |
126 ms |
1024 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Runtime error |
33 ms |
7032 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
0 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
1 ms |
384 KB |
correct |
8 |
Correct |
1 ms |
512 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
0 ms |
384 KB |
correct |
14 |
Correct |
3 ms |
384 KB |
correct |
15 |
Correct |
3 ms |
384 KB |
correct |
16 |
Correct |
3 ms |
360 KB |
correct |
17 |
Correct |
3 ms |
384 KB |
correct |
18 |
Correct |
2 ms |
384 KB |
correct |
19 |
Correct |
3 ms |
384 KB |
correct |
20 |
Correct |
4 ms |
384 KB |
correct |
21 |
Correct |
3 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
34 |
Correct |
302 ms |
1408 KB |
correct |
35 |
Correct |
290 ms |
1784 KB |
correct |
36 |
Correct |
201 ms |
1408 KB |
correct |
37 |
Correct |
18 ms |
384 KB |
correct |
38 |
Correct |
296 ms |
1692 KB |
correct |
39 |
Correct |
264 ms |
1536 KB |
correct |
40 |
Correct |
197 ms |
1408 KB |
correct |
41 |
Correct |
300 ms |
1664 KB |
correct |
42 |
Correct |
304 ms |
1692 KB |
correct |
43 |
Correct |
155 ms |
1272 KB |
correct |
44 |
Correct |
127 ms |
896 KB |
correct |
45 |
Correct |
150 ms |
1024 KB |
correct |
46 |
Correct |
118 ms |
1016 KB |
correct |
47 |
Correct |
51 ms |
640 KB |
correct |
48 |
Correct |
7 ms |
384 KB |
correct |
49 |
Correct |
17 ms |
384 KB |
correct |
50 |
Correct |
51 ms |
640 KB |
correct |
51 |
Correct |
153 ms |
1024 KB |
correct |
52 |
Correct |
129 ms |
1016 KB |
correct |
53 |
Correct |
116 ms |
896 KB |
correct |
54 |
Correct |
155 ms |
1272 KB |
correct |
55 |
Correct |
135 ms |
1172 KB |
correct |
56 |
Correct |
134 ms |
1024 KB |
correct |
57 |
Correct |
126 ms |
1024 KB |
correct |
58 |
Correct |
1 ms |
384 KB |
correct |
59 |
Correct |
1 ms |
384 KB |
correct |
60 |
Runtime error |
33 ms |
7032 KB |
Execution killed with signal 11 |
61 |
Halted |
0 ms |
0 KB |
- |