#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 3e5 + 10;
vector <pair <int, int>> ed[N];
int p[N][19], in[N], ou[N], timer = 0, id[N], cc = 1, a[N], b[N], used[N], w[N], f[N];
void dfs(int u, int v) {
p[u][0] = v;
for (int j = 1; j < 19; j++) {
p[u][j] = p[p[u][j - 1]][j - 1];
}
timer++;
in[u] = timer;
for (auto x : ed[u]) {
if (x.f == v)
continue;
id[x.f] = x.s;
dfs(x.f, u);
}
ou[u] = timer;
}
bool is(int a, int b) {
return in[a] <= in[b] && ou[a] >= ou[b];
}
int lca(int a, int b) {
if (is(a, b))
return a;
if (is(b, a))
return b;
for (int j = 18; j >= 0; j--) {
if (is(p[a][j], b) == 0)
a = p[a][j];
}
return p[a][0];
}
void upd(int i, int x) {
for (; i < N; i += i & (-i))
f[i] += x;
}
int get(int i) {
i = in[i];
int s = 0;
for (;i ; i -= i & (-i))
s += f[i];
return s;
}
vector <int> lst;
void path(int a, int c) {
while (1) {
int val = get(a);
for (int j = 18; j >= 0; j--) {
if (get(p[a][j]) == val)
a = p[a][j];
}
if (is(a, c))
break;
lst.pb(id[a]);
upd(in[a], -1);
upd(ou[a] + 1, 1);
a = p[a][0];
}
}
void road(int a, int b) {
int c = lca(a, b);
path(a, c);
path(b, c);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
in[0] = 0;
ou[0] = 1e9;
int n, e;
cin >> n >> e;
for (int i = 1; i <= e; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i < n; i++) {
int x;
cin >> x;
used[x] = 1;
ed[a[x]].pb({b[x], x});
ed[b[x]].pb({a[x], x});
}
dfs(1, 0);
for (int i = 2; i <= n; i++) {
upd(in[i], 1);
upd(ou[i] + 1, -1);
}
for (int i = 1; i <= e; i++) {
if (used[i] == 0) {
road(a[i], b[i]);
sort(all(lst));
for (auto x : lst) {
w[x] = cc++;
}
lst.clear();
}
if (w[i] == 0) {
w[i] = cc++;
if (used[i]) {
upd(in[i], -1);
upd(ou[i] + 1, 1);
}
}
cout << w[i] << " ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
18524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
18524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2057 ms |
31184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2033 ms |
37580 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
185 ms |
55756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
134 ms |
45072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
18524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |