結果
| 問題 |
No.1898 Battle and Exchange
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2022-04-08 22:52:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 683 ms / 5,000 ms |
| コード長 | 3,200 bytes |
| コンパイル時間 | 2,377 ms |
| コンパイル使用メモリ | 214,652 KB |
| 最終ジャッジ日時 | 2025-01-28 16:35:41 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 58 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
template <typename CostType>
struct Edge {
int src, dst;
CostType cost;
explicit Edge(const int src, const int dst, const CostType cost = 0)
: src(src), dst(dst), cost(cost) {}
inline bool operator<(const Edge& x) const {
if (cost != x.cost) return cost < x.cost;
return src != x.src ? src < x.src : dst < x.dst;
}
inline bool operator<=(const Edge& x) const { return !(x < *this); }
inline bool operator>(const Edge& x) const { return x < *this; }
inline bool operator>=(const Edge& x) const { return !(*this < x); }
};
int main() {
int n, m; cin >> n >> m;
vector<vector<int>> graph(n);
while (m--) {
int u, v; cin >> u >> v; --u; --v;
graph[u].emplace_back(v);
graph[v].emplace_back(u);
}
vector<vector<int>> cards(n);
vector<int> sum(n);
int ub = 4;
REP(i, n) {
int a, b, c; cin >> a >> b >> c;
cards[i] = {a, b, c};
sort(ALL(cards[i]));
sum[i] = a + b + c;
chmax(ub, a + b + c + 1);
}
REP(i, n) sort(ALL(graph[i]), [&](int a, int b) -> bool { return sum[a] < sum[b]; });
int lb = max({sum[0], sum[graph[0].front()] - cards[0].back() + 1, 3});
// assert(lb < ub);
while (ub - lb > 1) {
const int mid = (lb + ub) / 2;
vector<int> is_visited(n, -1), top3{mid - 2, 1, 1};
auto merge = [&](int i) -> void {
for (int e : cards[i]) top3.emplace_back(e);
sort(ALL(top3), greater<int>());
top3.resize(3);
};
is_visited[0] = is_visited[graph[0].front()] = 1;
merge(0);
merge(graph[0].front());
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
FOR(i, 1, graph[0].size()) {
const int e = graph[0][i];
is_visited[e] = 0;
que.emplace(sum[e], e);
}
for (int e : graph[graph[0].front()]) {
if (e != 0) {
is_visited[e] = 0;
que.emplace(sum[e], e);
}
}
while (!que.empty()) {
const int i = que.top().second; que.pop();
if (accumulate(ALL(top3), 0) <= sum[i]) break;
is_visited[i] = 1;
merge(i);
for (int e : graph[i]) {
if (is_visited[e] == -1) {
is_visited[e] = 0;
que.emplace(sum[e], e);
}
}
}
(is_visited[n - 1] == 1 ? ub : lb) = mid;
}
cout << "1 1 " << ub - 2 << '\n';
return 0;
}
emthrm