# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
58529 |
2018-07-18T05:00:39 Z |
Crown |
Simurgh (IOI17_simurgh) |
C++14 |
|
225 ms |
8444 KB |
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
// int count_common_roads(vector<int> vec)
const int maxn = 505;
const int maxm = maxn*maxn/2;
int n, m;
int edgeID[maxn][maxn];
vector<int> U, V;
vector<int> adj[maxn];
int par[maxn];
bool vis[maxn];
int dep[maxn];
int tree_score[maxm];
bool isInTree[maxm];
bool isNotBridge[maxm];
bool res[maxm];
vector<int> backedges;
vector<int> output;
void find_tree(int u = 0, int p = -1)
{
if(p != -1) par[u] = p;
vis[u] = true;
for(auto v : adj[u])
{
if(!vis[v])
{
dep[v] = dep[u]+1;
find_tree(v, u);
isInTree[edgeID[u][v]] = true;
output.push_back(edgeID[u][v]);
}
else if(v != p)
{
backedges.pb(edgeID[u][v]);
}
}
}
bool cmp(int a, int b)
{
int ua = U[a], ub = U[b];
int va = V[a], vb = V[b];
return min(dep[ua], dep[va])< min(dep[ub], dep[vb]);
}
void delete_from_output(int u)
{
vector<int> nou;
for(auto x : output)
{
if(x == u) continue;
nou.pb(x);
}
output = nou;
}
void add_to_output(int u)
{
output.pb(u);
}
int ask()
{
return count_common_roads(output);
}
vector<int> find_roads(int _n, vector<int> _u, vector<int> _v)
{
memset(tree_score, -1, sizeof tree_score);
n = _n; m = _u.size();
U = _u; V = _v;
for(int i = 0; i< m; i++)
{
int u = U[i], v = V[i];
edgeID[u][v] = edgeID[v][u] = i;
adj[u].pb(v); adj[v].pb(u);
}
dep[0] = 1; find_tree();
sort(backedges.begin(), backedges.end());
backedges.resize(unique(backedges.begin(), backedges.end())-backedges.begin());
sort(backedges.begin(), backedges.end(), cmp);
int base_score = ask();
for(auto edge : backedges)
{
int u = U[edge], v = V[edge];
if(dep[u]< dep[v]) swap(u, v);
int cur = u;
int sample = -1;
bool not_asked = true;
while(cur != v)
{
int tp = par[cur];
int id = edgeID[cur][tp];
if(tree_score[id] != -1)
{
not_asked = false;
sample = id;
}
cur = tp;
}
if(not_asked)
{
// printf("edge %d covering not asked\n", edge);
cur = u;
add_to_output(edge);
int mn = base_score, mx = base_score;
while(cur != v)
{
int tp = par[cur];
int id = edgeID[cur][tp];
isNotBridge[id] = true;
delete_from_output(id);
tree_score[id] = ask();
mn = min(tree_score[id], mn);
mx = max(tree_score[id], mx);
add_to_output(id);
cur = tp;
}
delete_from_output(edge);
cur = u;
while(cur != v)
{
int tp = par[cur];
int id = edgeID[cur][tp];
if(mn == mx) res[id] = false;
else if(tree_score[id] == mn) res[id] = true;
else res[id] = false;
// printf("res[%d] = %d\n", id, res[id]);
cur = tp;
}
if(mn != mx && base_score == mn) res[edge] = true;
// printf("res[%d] = %d\n", edge, res[edge]);
}
else
{
// printf("edge %d covering some asked\n", edge);
// printf("sample = %d\n", sample);
delete_from_output(sample);
add_to_output(edge);
int mod_score = base_score-res[sample];
tree_score[edge] = ask();
if(tree_score[edge]> mod_score) res[edge] = true;
else res[edge] = false;
// printf("res[%d] = %d\n", edge, res[edge]);
add_to_output(sample);
cur = u;
while(cur != v)
{
int tp = par[cur];
int id = edgeID[cur][tp];
isNotBridge[id] = true;
if(tree_score[id] != -1)
{
cur = tp; continue;
}
// printf("det'ing %d\n", id);
delete_from_output(id);
tree_score[id] = ask();
int mod_score = base_score+res[edge];
// printf("mod_score = %d\n", mod_score);
// printf("tree_score[%d] = %d\n", id, tree_score[id]);
if(tree_score[id]< mod_score) res[id] = true;
else res[id] = false;
// printf("res[%d] = %d\n", id, res[id]);
add_to_output(id);
cur = tp;
}
delete_from_output(edge);
}
}
output.clear();
for(int i = 0; i< m; i++)
{
if((!isNotBridge[i] and isInTree[i]) or res[i]) output.pb(i);
}
assert(ask() == n-1);
return output;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
888 KB |
correct |
2 |
Correct |
3 ms |
956 KB |
correct |
3 |
Correct |
3 ms |
956 KB |
correct |
4 |
Correct |
3 ms |
956 KB |
correct |
5 |
Correct |
2 ms |
1056 KB |
correct |
6 |
Correct |
4 ms |
1056 KB |
correct |
7 |
Correct |
3 ms |
1188 KB |
correct |
8 |
Correct |
3 ms |
1188 KB |
correct |
9 |
Correct |
4 ms |
1188 KB |
correct |
10 |
Correct |
3 ms |
1188 KB |
correct |
11 |
Correct |
2 ms |
1188 KB |
correct |
12 |
Correct |
3 ms |
1192 KB |
correct |
13 |
Correct |
3 ms |
1192 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
888 KB |
correct |
2 |
Correct |
3 ms |
956 KB |
correct |
3 |
Correct |
3 ms |
956 KB |
correct |
4 |
Correct |
3 ms |
956 KB |
correct |
5 |
Correct |
2 ms |
1056 KB |
correct |
6 |
Correct |
4 ms |
1056 KB |
correct |
7 |
Correct |
3 ms |
1188 KB |
correct |
8 |
Correct |
3 ms |
1188 KB |
correct |
9 |
Correct |
4 ms |
1188 KB |
correct |
10 |
Correct |
3 ms |
1188 KB |
correct |
11 |
Correct |
2 ms |
1188 KB |
correct |
12 |
Correct |
3 ms |
1192 KB |
correct |
13 |
Correct |
3 ms |
1192 KB |
correct |
14 |
Correct |
9 ms |
1260 KB |
correct |
15 |
Correct |
8 ms |
1260 KB |
correct |
16 |
Correct |
8 ms |
1260 KB |
correct |
17 |
Correct |
6 ms |
1260 KB |
correct |
18 |
Correct |
5 ms |
1260 KB |
correct |
19 |
Correct |
5 ms |
1260 KB |
correct |
20 |
Correct |
5 ms |
1260 KB |
correct |
21 |
Correct |
5 ms |
1260 KB |
correct |
22 |
Correct |
4 ms |
1260 KB |
correct |
23 |
Correct |
4 ms |
1260 KB |
correct |
24 |
Correct |
4 ms |
1276 KB |
correct |
25 |
Correct |
3 ms |
1276 KB |
correct |
26 |
Correct |
4 ms |
1276 KB |
correct |
27 |
Correct |
4 ms |
1384 KB |
correct |
28 |
Correct |
3 ms |
1384 KB |
correct |
29 |
Correct |
3 ms |
1384 KB |
correct |
30 |
Correct |
7 ms |
1384 KB |
correct |
31 |
Correct |
4 ms |
1384 KB |
correct |
32 |
Correct |
5 ms |
1384 KB |
correct |
33 |
Correct |
5 ms |
1384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
888 KB |
correct |
2 |
Correct |
3 ms |
956 KB |
correct |
3 |
Correct |
3 ms |
956 KB |
correct |
4 |
Correct |
3 ms |
956 KB |
correct |
5 |
Correct |
2 ms |
1056 KB |
correct |
6 |
Correct |
4 ms |
1056 KB |
correct |
7 |
Correct |
3 ms |
1188 KB |
correct |
8 |
Correct |
3 ms |
1188 KB |
correct |
9 |
Correct |
4 ms |
1188 KB |
correct |
10 |
Correct |
3 ms |
1188 KB |
correct |
11 |
Correct |
2 ms |
1188 KB |
correct |
12 |
Correct |
3 ms |
1192 KB |
correct |
13 |
Correct |
3 ms |
1192 KB |
correct |
14 |
Correct |
9 ms |
1260 KB |
correct |
15 |
Correct |
8 ms |
1260 KB |
correct |
16 |
Correct |
8 ms |
1260 KB |
correct |
17 |
Correct |
6 ms |
1260 KB |
correct |
18 |
Correct |
5 ms |
1260 KB |
correct |
19 |
Correct |
5 ms |
1260 KB |
correct |
20 |
Correct |
5 ms |
1260 KB |
correct |
21 |
Correct |
5 ms |
1260 KB |
correct |
22 |
Correct |
4 ms |
1260 KB |
correct |
23 |
Correct |
4 ms |
1260 KB |
correct |
24 |
Correct |
4 ms |
1276 KB |
correct |
25 |
Correct |
3 ms |
1276 KB |
correct |
26 |
Correct |
4 ms |
1276 KB |
correct |
27 |
Correct |
4 ms |
1384 KB |
correct |
28 |
Correct |
3 ms |
1384 KB |
correct |
29 |
Correct |
3 ms |
1384 KB |
correct |
30 |
Correct |
7 ms |
1384 KB |
correct |
31 |
Correct |
4 ms |
1384 KB |
correct |
32 |
Correct |
5 ms |
1384 KB |
correct |
33 |
Correct |
5 ms |
1384 KB |
correct |
34 |
Correct |
205 ms |
2940 KB |
correct |
35 |
Correct |
204 ms |
3080 KB |
correct |
36 |
Correct |
157 ms |
3080 KB |
correct |
37 |
Correct |
13 ms |
3080 KB |
correct |
38 |
Correct |
197 ms |
3644 KB |
correct |
39 |
Correct |
167 ms |
3644 KB |
correct |
40 |
Correct |
163 ms |
3644 KB |
correct |
41 |
Correct |
225 ms |
4124 KB |
correct |
42 |
Correct |
223 ms |
4232 KB |
correct |
43 |
Correct |
110 ms |
4232 KB |
correct |
44 |
Correct |
115 ms |
4232 KB |
correct |
45 |
Correct |
101 ms |
4232 KB |
correct |
46 |
Correct |
74 ms |
4232 KB |
correct |
47 |
Correct |
42 ms |
4232 KB |
correct |
48 |
Correct |
5 ms |
4232 KB |
correct |
49 |
Correct |
13 ms |
4232 KB |
correct |
50 |
Correct |
33 ms |
4232 KB |
correct |
51 |
Correct |
101 ms |
4304 KB |
correct |
52 |
Correct |
102 ms |
4304 KB |
correct |
53 |
Correct |
116 ms |
4304 KB |
correct |
54 |
Correct |
109 ms |
4816 KB |
correct |
55 |
Correct |
112 ms |
4816 KB |
correct |
56 |
Correct |
118 ms |
4816 KB |
correct |
57 |
Correct |
157 ms |
4880 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4880 KB |
correct |
2 |
Correct |
3 ms |
4880 KB |
correct |
3 |
Incorrect |
224 ms |
8444 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
888 KB |
correct |
2 |
Correct |
3 ms |
956 KB |
correct |
3 |
Correct |
3 ms |
956 KB |
correct |
4 |
Correct |
3 ms |
956 KB |
correct |
5 |
Correct |
2 ms |
1056 KB |
correct |
6 |
Correct |
4 ms |
1056 KB |
correct |
7 |
Correct |
3 ms |
1188 KB |
correct |
8 |
Correct |
3 ms |
1188 KB |
correct |
9 |
Correct |
4 ms |
1188 KB |
correct |
10 |
Correct |
3 ms |
1188 KB |
correct |
11 |
Correct |
2 ms |
1188 KB |
correct |
12 |
Correct |
3 ms |
1192 KB |
correct |
13 |
Correct |
3 ms |
1192 KB |
correct |
14 |
Correct |
9 ms |
1260 KB |
correct |
15 |
Correct |
8 ms |
1260 KB |
correct |
16 |
Correct |
8 ms |
1260 KB |
correct |
17 |
Correct |
6 ms |
1260 KB |
correct |
18 |
Correct |
5 ms |
1260 KB |
correct |
19 |
Correct |
5 ms |
1260 KB |
correct |
20 |
Correct |
5 ms |
1260 KB |
correct |
21 |
Correct |
5 ms |
1260 KB |
correct |
22 |
Correct |
4 ms |
1260 KB |
correct |
23 |
Correct |
4 ms |
1260 KB |
correct |
24 |
Correct |
4 ms |
1276 KB |
correct |
25 |
Correct |
3 ms |
1276 KB |
correct |
26 |
Correct |
4 ms |
1276 KB |
correct |
27 |
Correct |
4 ms |
1384 KB |
correct |
28 |
Correct |
3 ms |
1384 KB |
correct |
29 |
Correct |
3 ms |
1384 KB |
correct |
30 |
Correct |
7 ms |
1384 KB |
correct |
31 |
Correct |
4 ms |
1384 KB |
correct |
32 |
Correct |
5 ms |
1384 KB |
correct |
33 |
Correct |
5 ms |
1384 KB |
correct |
34 |
Correct |
205 ms |
2940 KB |
correct |
35 |
Correct |
204 ms |
3080 KB |
correct |
36 |
Correct |
157 ms |
3080 KB |
correct |
37 |
Correct |
13 ms |
3080 KB |
correct |
38 |
Correct |
197 ms |
3644 KB |
correct |
39 |
Correct |
167 ms |
3644 KB |
correct |
40 |
Correct |
163 ms |
3644 KB |
correct |
41 |
Correct |
225 ms |
4124 KB |
correct |
42 |
Correct |
223 ms |
4232 KB |
correct |
43 |
Correct |
110 ms |
4232 KB |
correct |
44 |
Correct |
115 ms |
4232 KB |
correct |
45 |
Correct |
101 ms |
4232 KB |
correct |
46 |
Correct |
74 ms |
4232 KB |
correct |
47 |
Correct |
42 ms |
4232 KB |
correct |
48 |
Correct |
5 ms |
4232 KB |
correct |
49 |
Correct |
13 ms |
4232 KB |
correct |
50 |
Correct |
33 ms |
4232 KB |
correct |
51 |
Correct |
101 ms |
4304 KB |
correct |
52 |
Correct |
102 ms |
4304 KB |
correct |
53 |
Correct |
116 ms |
4304 KB |
correct |
54 |
Correct |
109 ms |
4816 KB |
correct |
55 |
Correct |
112 ms |
4816 KB |
correct |
56 |
Correct |
118 ms |
4816 KB |
correct |
57 |
Correct |
157 ms |
4880 KB |
correct |
58 |
Correct |
3 ms |
4880 KB |
correct |
59 |
Correct |
3 ms |
4880 KB |
correct |
60 |
Incorrect |
224 ms |
8444 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |