提出 #66371240


ソースコード 拡げる

// 綺麗に解きなおし

#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;

/////////////////// メイン ///////////////////

int main () {
  
  //////////////////// 入力 ////////////////////

  int n, m;
  cin >> n >> m;

  // グラフを構築せず、vectorをそのまま受け取り0始まりに直しておくだけ
  vector<int> u(m), v(m), w(m);
  for (int i=0; i<m; i++) {
    cin >> u.at(i) >> v.at(i) >> w.at(i);
    u.at(i)--;
    v.at(i)--;
  }

  //////////////// 出力変数定義 ////////////////

  int result = 0;

  //////////////////// 処理 ////////////////////

  // 通行禁止ビットを管理する変数(ビット列と見なす)
  int forbidden = 0;

  // 上位のビットから順に確認
  for (int i=29; i>=0; i--) {

    // 仮にそのビットを禁止にしてみる
    forbidden ^= (1<<i);

    // UnionFind木を用意し、禁止されていない道だけでゴールできるか確認する
    dsu d(n);
    for (int i=0; i<m; i++) {
      if ((w.at(i)&forbidden)==0) {
        d.merge(u.at(i),v.at(i));
      }
    }

    // 禁止しちゃダメなところだった場合、禁止を解除
    if (!d.same(0,n-1)) forbidden ^= (1<<i);

  }

  // 禁止にできなかったビットを求める
  result = ((1<<30)-1)^forbidden;

  //////////////////// 出力 ////////////////////

  cout << result << endl;

  //////////////////// 終了 ////////////////////

  return 0;

}

提出情報

提出日時
問題 E - Minimum OR Path
ユーザ wightou
言語 C++ 23 (gcc 12.2)
得点 450
コード長 1545 Byte
結果 AC
実行時間 179 ms
メモリ 6268 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 35
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3384 KiB
00_sample_01.txt AC 1 ms 3496 KiB
00_sample_02.txt AC 1 ms 3448 KiB
01_handmade_00.txt AC 1 ms 3508 KiB
01_handmade_01.txt AC 1 ms 3508 KiB
01_handmade_02.txt AC 89 ms 5528 KiB
01_handmade_03.txt AC 89 ms 5508 KiB
01_handmade_04.txt AC 1 ms 3632 KiB
01_handmade_05.txt AC 1 ms 3516 KiB
01_handmade_06.txt AC 1 ms 3632 KiB
01_handmade_07.txt AC 117 ms 5692 KiB
01_handmade_08.txt AC 119 ms 5716 KiB
01_handmade_09.txt AC 119 ms 5736 KiB
02_random_00.txt AC 108 ms 4984 KiB
02_random_01.txt AC 86 ms 4952 KiB
02_random_02.txt AC 65 ms 4460 KiB
02_random_03.txt AC 122 ms 5480 KiB
02_random_04.txt AC 124 ms 5432 KiB
02_random_05.txt AC 107 ms 5092 KiB
02_random_06.txt AC 108 ms 5156 KiB
02_random_07.txt AC 137 ms 5692 KiB
02_random_08.txt AC 176 ms 6028 KiB
02_random_09.txt AC 107 ms 4976 KiB
02_random_10.txt AC 150 ms 5824 KiB
02_random_11.txt AC 172 ms 5988 KiB
02_random_12.txt AC 143 ms 6024 KiB
02_random_13.txt AC 154 ms 6132 KiB
02_random_14.txt AC 170 ms 6220 KiB
02_random_15.txt AC 114 ms 5424 KiB
02_random_16.txt AC 101 ms 5000 KiB
02_random_17.txt AC 104 ms 4956 KiB
02_random_18.txt AC 110 ms 4924 KiB
02_random_19.txt AC 169 ms 6224 KiB
02_random_20.txt AC 173 ms 6220 KiB
02_random_21.txt AC 179 ms 6268 KiB