#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mlog = 18;
int n, m, k;
int a[maxn], act[maxn];
int head[maxn];
vector<pair<int,int>> way[maxn];
pair<int,int> par[maxn];
int h[maxn];
vector<int> ord;
int mx[maxn];
int res[1005][1005];
void dfs(int u, int last) {
h[u] = h[last] + 1;
for(auto tmp : way[u]) {
int v = tmp.first, val = tmp.second;
if(v == last) continue;
par[v] = {u, val};
dfs(v, u);
}
ord.push_back(u);
}
int findhead(int x) {
if(x==head[x]) return x;
return head[x] = findhead(head[x]);
}
void solve() {
for(int x=1;x<=k;++x) {
for(int u=1;u<=n;++u) {
mx[u] = 0;
if(a[u] == x) mx[u] = m;
}
for(int i=0;i<n;++i) {
int u = ord[i];
int v = par[u].first, val = par[u].second;
int nxt = min(mx[u], val);
if(h[v] < h[u] && mx[v] < nxt) mx[v] = nxt;
}
for(int i=n-1;i>=0;--i) {
int u = ord[i];
for(auto tmp : way[u]) {
int v = tmp.first, val = tmp.second;
int nxt = min(mx[u], val);
if(h[v] >= h[u] && mx[v] < nxt) mx[v] = nxt;
}
}
for(int u=1;u<=n;u++) {
if(res[x][a[u]] < mx[u]) res[x][a[u]] = mx[u];
}
}
}
void Init(int K, vector<int> col, vector<int> s, vector<int> e) {
n = col.size(); m = s.size(); k = K;
for(int i=1;i<=n;++i) a[i] = col[i-1] + 1;
for(int i=1;i<=n;++i) head[i] = i;
for(int i=m;i>=1;--i) {
int x = s[i-1] + 1, y = e[i-1] + 1;
if(findhead(x) != findhead(y)) {
head[findhead(x)] = findhead(y);
way[x].push_back({y, i});
way[y].push_back({x, i});
}
}
dfs(1,0);
solve();
}
int Separate(int x, int y) {
++x; ++y;
return res[x][y];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5101 ms |
17248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Correct |
7 ms |
2816 KB |
Output is correct |
3 |
Correct |
221 ms |
15168 KB |
Output is correct |
4 |
Correct |
310 ms |
15076 KB |
Output is correct |
5 |
Correct |
523 ms |
15200 KB |
Output is correct |
6 |
Correct |
926 ms |
15332 KB |
Output is correct |
7 |
Correct |
1399 ms |
15588 KB |
Output is correct |
8 |
Correct |
3394 ms |
16096 KB |
Output is correct |
9 |
Execution timed out |
5100 ms |
16608 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Correct |
7 ms |
2816 KB |
Output is correct |
3 |
Execution timed out |
5101 ms |
17248 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |