mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 17:16:28 +00:00
Compare commits
No commits in common. "746fe02ec039061c92f0f9eec15a92b8eee0ea1e" and "3bb90b57d033b238bbe141016786a0b6e906dd17" have entirely different histories.
746fe02ec0
...
3bb90b57d0
@ -1,75 +0,0 @@
|
||||
#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;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 105;
|
||||
const int dx[] = {2, 2, -2, -2, 1, 1, -1, -1},
|
||||
dy[] = {1, -1, 1, -1, 2, -2, 2, -2};
|
||||
|
||||
int n, m, t, ans;
|
||||
std::pair<int, int> match[N][N];
|
||||
bool disabled[N][N], vis[N][N];
|
||||
|
||||
bool dfs(int x, int y) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int xx = x + dx[i],
|
||||
yy = y + dy[i];
|
||||
|
||||
if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
|
||||
if (disabled[xx][yy] || vis[xx][yy]) continue;
|
||||
|
||||
vis[xx][yy] = true;
|
||||
|
||||
auto t = match[xx][yy];
|
||||
|
||||
if (!t.first || dfs(t.first, t.second)) {
|
||||
match[xx][yy] = std::make_pair(x, y);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m >> t;
|
||||
|
||||
for (int i = 1; i <= t; i++) {
|
||||
int x, y;
|
||||
|
||||
cin >> x >> y;
|
||||
|
||||
disabled[x][y] = true;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= m; j++) {
|
||||
if (disabled[i][j] || (i + j) % 2) continue;
|
||||
|
||||
memset(vis, 0x00, sizeof(vis));
|
||||
if (dfs(i, j)) ans++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << n * m - t - ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
AcWing/378/data/1.ans
(Stored with Git LFS)
BIN
AcWing/378/data/1.ans
(Stored with Git LFS)
Binary file not shown.
BIN
AcWing/378/data/1.in
(Stored with Git LFS)
BIN
AcWing/378/data/1.in
(Stored with Git LFS)
Binary file not shown.
Loading…
Reference in New Issue
Block a user