結果

問題 No.3482 Quod Erat Demonstrandum
コンテスト
ユーザー toppo57
提出日時 2026-10-27 10:45:55
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 272 ms / 2,000 ms
+ 263µs
コード長 1,266 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,162 ms
コンパイル使用メモリ 198,108 KB
実行使用メモリ 19,276 KB
最終ジャッジ日時 2026-10-27 10:46:21
合計ジャッジ時間 11,000 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
using pii = pair<int, int>;
using Graph = vector<vector<pii>>;

Graph G(200010);
int D[200010][2];

void bfs(int src){
    fill(&D[0][0], &D[0][0]+200010*2, -1);
    D[src][0]=0;
    queue<pii> Q;
    Q.push({src, 0});

    while(! Q.empty()){
        auto [cur, eq] = Q.front();
        Q.pop();
        for (auto [dst, fm]: G[cur]){
            if (eq==1 && fm==1) continue;
            if (D[dst][eq+fm]!=-1) continue;
            D[dst][eq+fm]=D[cur][eq]+1;
            Q.push({dst, eq+fm});
        }
    }
    return;
}

void solve(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; scanf("%d %d", &N, &M);
    for (int i=1;i<=N;i++) G[i].clear();
    for (int i=0;i<M;i++){
        int A, B, C; scanf("%d %d %d", &A, &B, &C);
        G[A].push_back({B, C-1});
        G[B].push_back({A, C-1});
    }
    bfs(1);
    if (D[N][0]==-1 && D[N][1]==-1) {
        printf("Unknown\n");
    }
    else if (D[N][0]!=-1){
        printf("Same\n%d\n", D[N][0]);
    }
    else{
        printf("Different\n%d\n", D[N][1]);
    }
    return;
}

int main(){
    int T; scanf("%d", &T);
    for (int scenario=0;scenario<T;scenario++) solve();
    return 0;
}
0