結果
| 問題 | 
                            No.1898 Battle and Exchange
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tnakao0123
                         | 
                    
| 提出日時 | 2022-04-09 12:02:42 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,392 bytes | 
| コンパイル時間 | 700 ms | 
| コンパイル使用メモリ | 61,980 KB | 
| 実行使用メモリ | 12,384 KB | 
| 最終ジャッジ日時 | 2024-11-29 09:23:11 | 
| 合計ジャッジ時間 | 16,881 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 56 WA * 2 | 
ソースコード
/* -*- coding: utf-8 -*-
 *
 * 1898.cc:  No.1898 Battle and Exchange - yukicoder
 */
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_S = 300000000;
/* typedef */
typedef vector<int> vi;
typedef pair<int,int> pii;
struct Card {
  int a, b, c;
  Card() {}
  Card(int _a, int _b, int _c): a(_a), b(_b), c(_c) {}
  Card(int s): a(1), b(1), c(s - 2) {}
  void sort() {
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b);
  }
  
  void read() { scanf("%d%d%d", &a, &b, &c); sort(); }
  void takeone(Card &cd) {
    if (a < cd.c) {
      swap(a, cd.c);
      sort(), cd.sort();
    }
  }
  void takeall(Card &cd) {
    while (a < cd.c) takeone(cd);
  }
  int sum() const { return a + b + c; }
  bool operator<(const Card &cd) const { return sum() < cd.sum(); }
  bool operator>(const Card &cd) const { return sum() > cd.sum(); }
  bool operator<=(const Card &cd) const { return sum() <= cd.sum(); }
  bool operator>=(const Card &cd) const { return sum() >= cd.sum(); }
};
/* global variables */
vi nbrs[MAX_N];
Card cds[MAX_N], vcds[MAX_N];
bool ds[MAX_N];
/* subroutines */
bool check(int n, int s) {
  Card ucd(s);
  if (cds[0] >= ucd) return false;
  copy(cds, cds + n, vcds);
  fill(ds, ds + n, false);
  ds[0] = true;
  int dn = 1;
  priority_queue<pii> q;
  q.push(pii(-vcds[0].sum(), 0));
  bool gl = false;
  while (! q.empty()) {
    pii up = q.top(); q.pop();
    int us = -up.first, u = up.second;
    if (us >= ucd.sum()) break;
    if (u == n - 1) {
      gl = true;
      break;
    }
    if (dn == 1) ucd.takeone(vcds[u]);
    else ucd.takeall(vcds[u]);
    for (auto v: nbrs[u]) {
      if (! ds[v]) {
	ds[v] = true;
	dn++;
	q.push(pii(-vcds[v].sum(), v));
      }
    }
    if (u == 0 && dn > 1) ucd.takeall(vcds[0]);
  }
  //printf("check(%d) = %d\n", s, gl);
  return gl;
}
/* main */
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    nbrs[u].push_back(v);
    nbrs[v].push_back(u);
  }
  for (int i = 0; i < n; i++) cds[i].read();
  int s0 = 3, s1 = MAX_S + 1;
  while (s0 + 1 < s1) {
    int s = (s0 + s1) / 2;
    if (check(n, s)) s1 = s;
    else s0 = s;
  }
  //printf("s1=%d\n", s1);
  printf("1 1 %d\n", s1 - 2);
  return 0;
}
            
            
            
        
            
tnakao0123