結果

問題 No.3482 Quod Erat Demonstrandum
コンテスト
ユーザー Dipanshu
提出日時 2026-03-28 14:13:52
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,501 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,564 ms
コンパイル使用メモリ 344,756 KB
実行使用メモリ 25,372 KB
最終ジャッジ日時 2026-03-28 14:14:00
合計ジャッジ時間 7,645 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

#define INF 1e9
vector<int> vis;
vector<pair<int,int>> dis;
vector<vector<pair<int,int>>> g;

void bfs(int st,int en)
{
    queue<pair<int,int>> qu;
    qu.push({st,0});
    dis[st] = {0,0};

    while (!qu.empty())
    {
        pair<int,int> curr = qu.front();qu.pop();
        // if (vis[curr.first]) continue;
        // vis[curr.first] = 1;

        for (auto v : g[curr.first])
        {
            if (dis[v.first].second>dis[curr.first].second+v.second)
            {
                dis[v.first].first = dis[curr.first].first+1;
                dis[v.first].second = dis[curr.first].second+v.second;
                qu.push({v.first,v.second+curr.second});
            }
        }
    }
}

void solve()
{
    g.clear();
    dis.clear();
    vis.clear();
    int n,m;cin>>n>>m;
    g.resize(n+1);
    dis.assign(n+1,{INF,INF});
    vis.assign(n+1,0);
    for (int i = 0; i < m; i++)
    {
        int x,y,z;cin>>x>>y>>z;
        g[x].push_back({y,z-1});
        g[y].push_back({x,z-1});
    }

    bfs(1,n);

    if (dis[n].second>1) cout << "Unknown" << endl;
    else if (dis[n].second==1) 
    {
        cout << "Different" << endl;
        cout << dis[n].first << endl;
    }
    else if (dis[n].second==0)
    {
        cout << "Same" << endl;
        cout << dis[n].first << endl;
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t;cin>>t;while(t--)
    solve();
}
0