# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
172295 |
2020-01-01T00:09:52 Z |
qkxwsm |
Simurgh (IOI17_simurgh) |
C++14 |
|
197 ms |
4088 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "simurgh.h"
using namespace std;
using namespace __gnu_pbds;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
struct custom_hash
{
template<class T>
T operator()(T a) const
{
return (a ^ (a >> 15)) ^ (a * 69);
}
};
template<class T, class U>
using hash_table = gp_hash_table<T, U, custom_hash>;
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define MAXN 513
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N, M, T;
int eid[MAXN][MAXN];
int st[MAXN], ft[MAXN];
hash_table<int, int> rec[MAXN];
vi edge[MAXN];
bitset<MAXN> seen;
int parent[MAXN], depth[MAXN];
int ans[MAXN * MAXN];
vi quer;
vi ret;
int get(int a, int b)
{
if (rec[a].find(b) != rec[a].end()) return rec[a][b];
quer.clear();
if (a == 0 && b == 0)
{
FOR(i, 1, N)
{
quer.PB(eid[i][parent[i]]);
}
rec[a][b] = count_common_roads(quer);
}
else
{
FOR(i, 1, N)
{
if (i == a) continue;
quer.PB(eid[i][parent[i]]);
}
quer.PB(b);
rec[a][b] = count_common_roads(quer);
}
return rec[a][b];
//take the tree, except delete a and add edge b.
}
void dfs(int u, int p)
{
st[u] = T; ft[u] = T;
T++;
seen[u] = true;
for (int v : edge[u])
{
if (v == p) continue;
if (seen[v])
{
ckmin(ft[u], st[v]);
continue;
}
parent[v] = u;
depth[v] = depth[u] + 1;
dfs(v, u);
ckmin(ft[u], ft[v]);
}
}
vi find_roads(int n, vi e1, vi e2)
{
N = n; M = SZ(e1);
FOR(i, 0, M)
{
edge[e1[i]].PB(e2[i]);
edge[e2[i]].PB(e1[i]);
eid[e1[i]][e2[i]] = i;
eid[e2[i]][e1[i]] = i;
ans[i] = -1;
}
parent[0] = N; parent[N] = N;
dfs(0, N);
// FOR(i, 1, N)
// {
// cerr << i << " -> " << parent[i] << endl;
// }
//1 = yes, -1 = no, 0 = idk
FOR(ed, 0, M)
{
int u = e1[ed], v = e2[ed];
if (depth[u] > depth[v]) swap(u, v);
if (u == parent[v]) continue;
//lol there are no side edges.
vi nodes; nodes.PB(v);
while(nodes.back() != u)
{
nodes.PB(parent[nodes.back()]);
}
assert(nodes.back() == u);
//you know the answer?
int s = -1;
FOR(i, 0, SZ(nodes) - 1)
{
if (ans[eid[nodes[i]][nodes[i + 1]]] != -1)
{
s = nodes[i];
break;
}
}
if (s == -1)
{
int mn = get(0, 0), mx = mn;
FOR(i, 0, SZ(nodes) - 1)
{
int x = get(nodes[i], ed);
ckmin(mn, x);
ckmax(mx, x);
}
FOR(i, 0, SZ(nodes) - 1)
{
int x = get(nodes[i], ed);
ans[eid[nodes[i]][nodes[i + 1]]] = ((mn == mx || x == mx) ? 0 : 1);
}
int x = get(0, 0);
ans[ed] = ((mn == mx || x == mx) ? 0 : 1);
}
else
{
int x = get(s, ed);
int y = get(0, 0);
//y + ed - s = x -> ed = x + s - y
ans[ed] = x + ans[eid[s][parent[s]]] - y;
FOR(i, 0, SZ(nodes) - 1)
{
int ed1 = eid[nodes[i]][nodes[i + 1]];
if (ans[ed1] != -1) continue;
x = get(nodes[i], ed);
//x = y + ed - ed1
ans[ed1] = y - x + ans[ed];
}
}
}
FOR(u, 1, N)
{
if (ans[eid[u][parent[u]]] == -1)
{
ans[eid[u][parent[u]]] = 1;
}
}
FOR(i, 0, M)
{
assert(ans[i] == 0 || ans[i] == 1);
if (ans[i] == 1) ret.PB(i);
}
// cerr << "RETURNS:";
// for (int x : ret)
// {
// cerr << ' ' << x;
// }
// cerr << endl;
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
correct |
2 |
Correct |
2 ms |
504 KB |
correct |
3 |
Correct |
2 ms |
504 KB |
correct |
4 |
Correct |
2 ms |
504 KB |
correct |
5 |
Correct |
2 ms |
504 KB |
correct |
6 |
Correct |
2 ms |
504 KB |
correct |
7 |
Correct |
2 ms |
376 KB |
correct |
8 |
Correct |
2 ms |
504 KB |
correct |
9 |
Correct |
2 ms |
504 KB |
correct |
10 |
Correct |
2 ms |
504 KB |
correct |
11 |
Correct |
2 ms |
504 KB |
correct |
12 |
Correct |
2 ms |
504 KB |
correct |
13 |
Correct |
2 ms |
508 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
correct |
2 |
Correct |
2 ms |
504 KB |
correct |
3 |
Correct |
2 ms |
504 KB |
correct |
4 |
Correct |
2 ms |
504 KB |
correct |
5 |
Correct |
2 ms |
504 KB |
correct |
6 |
Correct |
2 ms |
504 KB |
correct |
7 |
Correct |
2 ms |
376 KB |
correct |
8 |
Correct |
2 ms |
504 KB |
correct |
9 |
Correct |
2 ms |
504 KB |
correct |
10 |
Correct |
2 ms |
504 KB |
correct |
11 |
Correct |
2 ms |
504 KB |
correct |
12 |
Correct |
2 ms |
504 KB |
correct |
13 |
Correct |
2 ms |
508 KB |
correct |
14 |
Correct |
5 ms |
632 KB |
correct |
15 |
Correct |
4 ms |
632 KB |
correct |
16 |
Correct |
4 ms |
632 KB |
correct |
17 |
Correct |
4 ms |
632 KB |
correct |
18 |
Correct |
3 ms |
504 KB |
correct |
19 |
Correct |
4 ms |
632 KB |
correct |
20 |
Correct |
4 ms |
632 KB |
correct |
21 |
Correct |
4 ms |
632 KB |
correct |
22 |
Correct |
3 ms |
632 KB |
correct |
23 |
Correct |
3 ms |
632 KB |
correct |
24 |
Correct |
3 ms |
632 KB |
correct |
25 |
Correct |
2 ms |
632 KB |
correct |
26 |
Correct |
3 ms |
632 KB |
correct |
27 |
Correct |
3 ms |
632 KB |
correct |
28 |
Correct |
3 ms |
632 KB |
correct |
29 |
Correct |
2 ms |
632 KB |
correct |
30 |
Correct |
3 ms |
632 KB |
correct |
31 |
Correct |
3 ms |
632 KB |
correct |
32 |
Correct |
3 ms |
632 KB |
correct |
33 |
Correct |
3 ms |
632 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
correct |
2 |
Correct |
2 ms |
504 KB |
correct |
3 |
Correct |
2 ms |
504 KB |
correct |
4 |
Correct |
2 ms |
504 KB |
correct |
5 |
Correct |
2 ms |
504 KB |
correct |
6 |
Correct |
2 ms |
504 KB |
correct |
7 |
Correct |
2 ms |
376 KB |
correct |
8 |
Correct |
2 ms |
504 KB |
correct |
9 |
Correct |
2 ms |
504 KB |
correct |
10 |
Correct |
2 ms |
504 KB |
correct |
11 |
Correct |
2 ms |
504 KB |
correct |
12 |
Correct |
2 ms |
504 KB |
correct |
13 |
Correct |
2 ms |
508 KB |
correct |
14 |
Correct |
5 ms |
632 KB |
correct |
15 |
Correct |
4 ms |
632 KB |
correct |
16 |
Correct |
4 ms |
632 KB |
correct |
17 |
Correct |
4 ms |
632 KB |
correct |
18 |
Correct |
3 ms |
504 KB |
correct |
19 |
Correct |
4 ms |
632 KB |
correct |
20 |
Correct |
4 ms |
632 KB |
correct |
21 |
Correct |
4 ms |
632 KB |
correct |
22 |
Correct |
3 ms |
632 KB |
correct |
23 |
Correct |
3 ms |
632 KB |
correct |
24 |
Correct |
3 ms |
632 KB |
correct |
25 |
Correct |
2 ms |
632 KB |
correct |
26 |
Correct |
3 ms |
632 KB |
correct |
27 |
Correct |
3 ms |
632 KB |
correct |
28 |
Correct |
3 ms |
632 KB |
correct |
29 |
Correct |
2 ms |
632 KB |
correct |
30 |
Correct |
3 ms |
632 KB |
correct |
31 |
Correct |
3 ms |
632 KB |
correct |
32 |
Correct |
3 ms |
632 KB |
correct |
33 |
Correct |
3 ms |
632 KB |
correct |
34 |
Correct |
197 ms |
2908 KB |
correct |
35 |
Correct |
186 ms |
2936 KB |
correct |
36 |
Correct |
126 ms |
2464 KB |
correct |
37 |
Correct |
11 ms |
1016 KB |
correct |
38 |
Correct |
193 ms |
2924 KB |
correct |
39 |
Correct |
162 ms |
2808 KB |
correct |
40 |
Correct |
129 ms |
2396 KB |
correct |
41 |
Correct |
191 ms |
2960 KB |
correct |
42 |
Correct |
192 ms |
2936 KB |
correct |
43 |
Correct |
105 ms |
2168 KB |
correct |
44 |
Correct |
80 ms |
1960 KB |
correct |
45 |
Correct |
94 ms |
1904 KB |
correct |
46 |
Correct |
70 ms |
1736 KB |
correct |
47 |
Correct |
33 ms |
1272 KB |
correct |
48 |
Correct |
4 ms |
888 KB |
correct |
49 |
Correct |
11 ms |
1016 KB |
correct |
50 |
Correct |
31 ms |
1400 KB |
correct |
51 |
Correct |
91 ms |
1912 KB |
correct |
52 |
Correct |
79 ms |
1912 KB |
correct |
53 |
Correct |
70 ms |
1784 KB |
correct |
54 |
Correct |
104 ms |
2168 KB |
correct |
55 |
Correct |
96 ms |
2044 KB |
correct |
56 |
Correct |
97 ms |
2032 KB |
correct |
57 |
Correct |
97 ms |
2144 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
correct |
2 |
Correct |
2 ms |
504 KB |
correct |
3 |
Incorrect |
150 ms |
4088 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
correct |
2 |
Correct |
2 ms |
504 KB |
correct |
3 |
Correct |
2 ms |
504 KB |
correct |
4 |
Correct |
2 ms |
504 KB |
correct |
5 |
Correct |
2 ms |
504 KB |
correct |
6 |
Correct |
2 ms |
504 KB |
correct |
7 |
Correct |
2 ms |
376 KB |
correct |
8 |
Correct |
2 ms |
504 KB |
correct |
9 |
Correct |
2 ms |
504 KB |
correct |
10 |
Correct |
2 ms |
504 KB |
correct |
11 |
Correct |
2 ms |
504 KB |
correct |
12 |
Correct |
2 ms |
504 KB |
correct |
13 |
Correct |
2 ms |
508 KB |
correct |
14 |
Correct |
5 ms |
632 KB |
correct |
15 |
Correct |
4 ms |
632 KB |
correct |
16 |
Correct |
4 ms |
632 KB |
correct |
17 |
Correct |
4 ms |
632 KB |
correct |
18 |
Correct |
3 ms |
504 KB |
correct |
19 |
Correct |
4 ms |
632 KB |
correct |
20 |
Correct |
4 ms |
632 KB |
correct |
21 |
Correct |
4 ms |
632 KB |
correct |
22 |
Correct |
3 ms |
632 KB |
correct |
23 |
Correct |
3 ms |
632 KB |
correct |
24 |
Correct |
3 ms |
632 KB |
correct |
25 |
Correct |
2 ms |
632 KB |
correct |
26 |
Correct |
3 ms |
632 KB |
correct |
27 |
Correct |
3 ms |
632 KB |
correct |
28 |
Correct |
3 ms |
632 KB |
correct |
29 |
Correct |
2 ms |
632 KB |
correct |
30 |
Correct |
3 ms |
632 KB |
correct |
31 |
Correct |
3 ms |
632 KB |
correct |
32 |
Correct |
3 ms |
632 KB |
correct |
33 |
Correct |
3 ms |
632 KB |
correct |
34 |
Correct |
197 ms |
2908 KB |
correct |
35 |
Correct |
186 ms |
2936 KB |
correct |
36 |
Correct |
126 ms |
2464 KB |
correct |
37 |
Correct |
11 ms |
1016 KB |
correct |
38 |
Correct |
193 ms |
2924 KB |
correct |
39 |
Correct |
162 ms |
2808 KB |
correct |
40 |
Correct |
129 ms |
2396 KB |
correct |
41 |
Correct |
191 ms |
2960 KB |
correct |
42 |
Correct |
192 ms |
2936 KB |
correct |
43 |
Correct |
105 ms |
2168 KB |
correct |
44 |
Correct |
80 ms |
1960 KB |
correct |
45 |
Correct |
94 ms |
1904 KB |
correct |
46 |
Correct |
70 ms |
1736 KB |
correct |
47 |
Correct |
33 ms |
1272 KB |
correct |
48 |
Correct |
4 ms |
888 KB |
correct |
49 |
Correct |
11 ms |
1016 KB |
correct |
50 |
Correct |
31 ms |
1400 KB |
correct |
51 |
Correct |
91 ms |
1912 KB |
correct |
52 |
Correct |
79 ms |
1912 KB |
correct |
53 |
Correct |
70 ms |
1784 KB |
correct |
54 |
Correct |
104 ms |
2168 KB |
correct |
55 |
Correct |
96 ms |
2044 KB |
correct |
56 |
Correct |
97 ms |
2032 KB |
correct |
57 |
Correct |
97 ms |
2144 KB |
correct |
58 |
Correct |
2 ms |
504 KB |
correct |
59 |
Correct |
2 ms |
504 KB |
correct |
60 |
Incorrect |
150 ms |
4088 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |