mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 21:48:48 +00:00
Compare commits
2 Commits
b0cbb43a3f
...
b5f87613c9
Author | SHA1 | Date | |
---|---|---|---|
b5f87613c9 | |||
ef88d92c7b |
75
LibreOJ/2594/2594.cpp
Normal file
75
LibreOJ/2594/2594.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 20005;
|
||||||
|
|
||||||
|
int n, m;
|
||||||
|
std::array<int, N> color;
|
||||||
|
std::array<std::vector<std::pair<int, int>>, N> g;
|
||||||
|
|
||||||
|
bool dfs(int u, int color, int limit) {
|
||||||
|
::color[u] = color;
|
||||||
|
|
||||||
|
for (auto e : g[u]) {
|
||||||
|
int v = e.first,
|
||||||
|
w = e.second;
|
||||||
|
|
||||||
|
if (w <= limit) continue;
|
||||||
|
if (::color[v]) {
|
||||||
|
if (::color[v] == color) return false;
|
||||||
|
} else if (!dfs(v, 3 - color, limit)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check(int limit) {
|
||||||
|
std::fill(color.begin(), color.end(), 0);
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (!color[i]) {
|
||||||
|
if (!dfs(i, 1, limit)) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
for (int i = 1, u, v, w; i <= m; i++) {
|
||||||
|
cin >> u >> v >> w;
|
||||||
|
|
||||||
|
g[u].emplace_back(v, w);
|
||||||
|
g[v].emplace_back(u, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
int l = 0, r = 1e9, ans = 0;
|
||||||
|
|
||||||
|
while (l <= r) {
|
||||||
|
int mid = (l + r) >> 1;
|
||||||
|
|
||||||
|
if (check(mid)) {
|
||||||
|
ans = mid;
|
||||||
|
r = mid - 1;
|
||||||
|
} else {
|
||||||
|
l = mid + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
LibreOJ/2594/data/prison1.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison10.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison2.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison3.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison3.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison4.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison4.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison5.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison5.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison6.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison6.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison7.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison7.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison8.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison8.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison9.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison9.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2594/data/prison9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2594/data/prison9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
75
Luogu/P1525/P1525.cpp
Normal file
75
Luogu/P1525/P1525.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 20005;
|
||||||
|
|
||||||
|
int n, m;
|
||||||
|
std::array<int, N> color;
|
||||||
|
std::array<std::vector<std::pair<int, int>>, N> g;
|
||||||
|
|
||||||
|
bool dfs(int u, int color, int limit) {
|
||||||
|
::color[u] = color;
|
||||||
|
|
||||||
|
for (auto e : g[u]) {
|
||||||
|
int v = e.first,
|
||||||
|
w = e.second;
|
||||||
|
|
||||||
|
if (w <= limit) continue;
|
||||||
|
if (::color[v]) {
|
||||||
|
if (::color[v] == color) return false;
|
||||||
|
} else if (!dfs(v, 3 - color, limit)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check(int limit) {
|
||||||
|
std::fill(color.begin(), color.end(), 0);
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (!color[i]) {
|
||||||
|
if (!dfs(i, 1, limit)) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
for (int i = 1, u, v, w; i <= m; i++) {
|
||||||
|
cin >> u >> v >> w;
|
||||||
|
|
||||||
|
g[u].emplace_back(v, w);
|
||||||
|
g[v].emplace_back(u, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
int l = 0, r = 1e9, ans = 0;
|
||||||
|
|
||||||
|
while (l <= r) {
|
||||||
|
int mid = (l + r) >> 1;
|
||||||
|
|
||||||
|
if (check(mid)) {
|
||||||
|
ans = mid;
|
||||||
|
r = mid - 1;
|
||||||
|
} else {
|
||||||
|
l = mid + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
Luogu/P1525/data/P1525_1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_10.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_10.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_2.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_2.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_3.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_3.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_4.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_4.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_5.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_5.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_6.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_6.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_7.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_7.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_8.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_8.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_9.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P1525/data/P1525_9.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P1525/data/P1525_9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user