0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 16:18:49 +00:00

#1515. 【NOIP 十连测 Day 1】涂色 (colour)

https://sjzezoj.com/submission/60278
This commit is contained in:
Baoshuo Ren 2022-10-12 21:38:07 +08:00
parent 14ea5cc0e8
commit a2c574292e
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
58 changed files with 298 additions and 0 deletions

127
S2OJ/1515/1515.cpp Normal file
View File

@ -0,0 +1,127 @@
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5e5 + 5;
int n, m, cnt, father[N];
int dep[N], id[N], siz[N], fa[N], son[N], top[N], w[N];
std::tuple<int, int, bool, int> edges[N];
std::vector<std::pair<int, int>> g[N];
void dfs1(int u, int f) {
fa[u] = father[u] = f;
dep[u] = dep[f] + 1;
siz[u] = 1;
for (auto e : g[u]) {
int v = e.first,
i = e.second;
if (v == f) continue;
id[v] = i;
dfs1(v, u);
siz[u] += siz[v];
if (siz[son[u]] < siz[v]) son[u] = v;
}
}
void dfs2(int u, int t) {
top[u] = t;
if (!son[u]) return;
dfs2(son[u], t);
for (auto e : g[u]) {
int v = e.first;
if (v == fa[u]) continue;
if (v == son[u]) continue;
dfs2(v, v);
}
}
int lca(int u, int v) {
while (top[u] != top[v]) {
if (dep[top[u]] < dep[top[v]]) std::swap(u, v);
u = fa[top[u]];
}
return dep[u] < dep[v] ? u : v;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1, u, v, c; i <= m; i++) {
cin >> u >> v >> c;
if (c) {
g[u].emplace_back(v, i);
g[v].emplace_back(u, i);
}
edges[i] = std::make_tuple(u, v, c, 0);
}
dfs1(1, 1);
dfs2(1, 1);
for (int i = 1; i <= m; i++) {
if (std::get<3>(edges[i])) continue;
if (!std::get<2>(edges[i])) {
int u = std::get<0>(edges[i]),
v = std::get<1>(edges[i]),
l = lca(u, v);
std::vector<int> ids;
while (dep[u] > dep[l]) {
if (!std::get<3>(edges[id[u]])) {
ids.push_back(id[u]);
}
int t = father[u];
father[u] = l;
u = t;
}
while (dep[v] > dep[l]) {
if (!std::get<3>(edges[id[v]])) {
ids.push_back(id[v]);
}
int t = father[v];
father[v] = l;
v = t;
}
std::sort(ids.begin(), ids.end());
for (int id : ids) {
std::get<3>(edges[id]) = ++cnt;
}
}
std::get<3>(edges[i]) = ++cnt;
}
for (int i = 1; i <= m; i++) {
cout << std::get<3>(edges[i]) << ' ';
}
cout << endl;
return 0;
}

BIN
S2OJ/1515/data/colour1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour21.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour21.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour22.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour22.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour23.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour23.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour24.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour24.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour25.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour25.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/colour9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/ex_colour1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/ex_colour1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/ex_colour2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/ex_colour2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/ex_colour3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/ex_colour3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1515/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.