結果
| 問題 | 
                            No.1898 Battle and Exchange
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-04-08 22:02:05 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 3,423 bytes | 
| コンパイル時間 | 908 ms | 
| コンパイル使用メモリ | 140,316 KB | 
| 実行使用メモリ | 17,256 KB | 
| 最終ジャッジ日時 | 2024-06-22 14:50:57 | 
| 合計ジャッジ時間 | 16,850 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 WA * 1 | 
| other | AC * 53 WA * 5 | 
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }
bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }
int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }
enum INF = 10L^^18;
enum BIG = 10L^^9;
int N, M;
int[] A, B;
long[][] X;
int[][] G;
long need0, need1;
int[] us;
bool check(long[] start) {
  if (!(start.sum > need0)) {
    return false;
  }
  bool ok1 = false;
  foreach (k; 0 .. 3) {
    auto xs = start.dup;
    chmax(xs[k], X[0][k]);
    ok1 = ok1 || (xs.sum > need1);
  }
  if (!ok1) {
    return false;
  }
  
  auto xs = start.dup;
  foreach (u; us) {
    if (!(xs.sum > X[u].sum)) {
      return false;
    }
    foreach (k; 0 .. 3) {
      chmax(xs[k], X[u][k]);
    }
  }
  return true;
}
void main() {
  try {
    for (; ; ) {
      N = readInt;
      M = readInt;
      A = new int[M];
      B = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt - 1;
        B[i] = readInt - 1;
      }
      X = new long[][](N, 3);
      foreach (u; 0 .. N) foreach (k; 0 .. 3) {
        X[u][k] = readLong;
      }
      
      G = new int[][N];
      foreach (i; 0 .. M) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      
      need0 = X[0].sum;
      need1 = INF;
      foreach (i; G[0]) {
        const v = A[i] ^ B[i] ^ 0;
        chmin(need1, X[v].sum);
      }
      
      alias Entry = Tuple!(long, "c", int, "u");
      BinaryHeap!(Array!Entry, "a.c > b.c") que;
      auto vis = new bool[N];
      vis[0] = true;
      que.insert(Entry(X[0].sum, 0));
      us = [];
      for (; !que.empty; ) {
        const u = que.front.u;
        que.removeFront;
        us ~= u;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!vis[v]) {
            vis[v] = true;
            que.insert(Entry(X[v].sum, v));
          }
        }
      }
      debug {
        writeln("need0 = ", need0);
        writeln("need1 = ", need1);
        writeln("us = ", us);
      }
      
      long mn = INF;
      long[] ans;
      foreach (k; 0 .. 3) {
        long[] start = [1, 1, 1];
        long lo = 0, hi = BIG;
        for (; lo + 1 < hi; ) {
          const mid = (lo + hi) / 2;
          start[k] = mid;
          (check(start) ? hi : lo) = mid;
        }
        if (chmin(mn, hi)) {
          start[k] = hi;
          ans = start.dup;
        }
      }
      
      writeln(ans[0], " ", ans[1], " ", ans[2]);
    }
  } catch (EOFException e) {
  }
}