結果
| 問題 |
No.1898 Battle and Exchange
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-23 11:37:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,267 bytes |
| コンパイル時間 | 2,253 ms |
| コンパイル使用メモリ | 208,800 KB |
| 最終ジャッジ日時 | 2025-01-27 05:58:00 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 WA * 3 TLE * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | int n, m; scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d%d", &u[i], &v[i]); u[i]--; v[i]--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:15:41: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | for(int i = 0; i < n; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
int main() {
int n, m; scanf("%d%d", &n, &m);
std::vector<int> u(m), v(m), a(n), b(n), c(n);
std::vector<std::vector<int>> g(n);
for(int i = 0; i < m; i++) {
scanf("%d%d", &u[i], &v[i]); u[i]--; v[i]--;
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
for(int i = 0; i < n; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]);
if(n == 1) {
// no case exist
}
std::vector<i64> d(n);
for(int i = 0; i < n; i++) d[i] = (i64)a[i] + b[i] + c[i];
for(int i = 0; i < n; i++) {
int min = std::min({a[i], b[i], c[i]});
int max = std::max({a[i], b[i], c[i]});
a[i] = min;
b[i] = d[i] - min - max;
c[i] = max;
}
int min_v = g[0][0];
for(auto v: g[0]) {
if(d[v] < d[min_v]) min_v = v;
}
auto f = [&](i64 A, i64 B = 1, i64 C = 1) -> bool {
if(d[0] >= A + B + C) return false;
i64 min = std::min({A, B, C});
i64 max = std::max({A, B, C});
B = A + B + C - min - max; A = min; C = max;
// A <= B <= C
auto update = [&](int x) {
if(C < x) {
A = B;
B = C;
C = x;
} else if(B < x) {
A = B;
B = x;
} else if(A < x) {
A = x;
}
};
update(c[0]);
if(d[min_v] >= A + B + C) return false;
using P = std::pair<i64, int>;
std::priority_queue<P, std::vector<P>, std::greater<>> qu;
qu.push({d[0], 0});
std::vector<int> used(n); used[0] = true;
while(!qu.empty()) {
auto [sum, v] = qu.top(); qu.pop();
if(sum >= A + B + C) return false;
if(v == n - 1) return true;
update(a[v]);
update(b[v]);
update(c[v]);
for(int to: g[v]) {
if(used[to]) continue; used[to] = true;
qu.push({d[to], to});
}
}
return false;
};
i64 ng = 1, ok = 3'000'000'000LL;
while(ok - ng > 1) {
i64 mid = ng + (ok - ng) / 2;
if(f(mid)) ok = mid;
else ng = mid;
}
std::random_device seed;
std::mt19937 engine(seed());
auto get_random = [&](i64 x) {
std::uniform_int_distribution<long long> dist(0, x);
return dist(engine);
};
i64 sum = ok - 1;
while(true) {
i64 A = get_random(sum);
i64 B = get_random(sum - A);
i64 C = sum - A - B;
A++; B++; C++;
assert(A + B + C == ok + 2);
if(!f(A, B, C)) continue;
printf("%lld %lld %lld\n", A, B, C);
break;
}
// printf("%lld 1 1\n", ok);
return 0;
}