結果

問題 No.3482 Quod Erat Demonstrandum
コンテスト
ユーザー Dipanshu
提出日時 2026-03-28 13:36:40
言語 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
結果
WA  
実行時間 -
コード長 1,433 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,473 ms
コンパイル使用メモリ 344,380 KB
実行使用メモリ 24,528 KB
最終ジャッジ日時 2026-03-28 13:36:53
合計ジャッジ時間 9,343 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 30 WA * 15
権限があれば一括ダウンロードができます

ソースコード

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<int> dis;
vector<vector<pair<int,int>>> g;

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

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

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

void solve()
{
    g.clear();
    dis.clear();
    vis.clear();
    int n,m;cin>>n>>m;
    g.resize(n+1);
    dis.assign(n+1,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});
    }

    int dif = bfs(1,n);

    if (dif==-1 || dif>1) cout << "Unknown" << endl;
    else if (dif==1) 
    {
        cout << "Differently" << endl;
        cout << dis[n] << endl;
    }
    else if (dif==0)
    {
        cout << "Same" << endl;
        cout << dis[n] << endl;
    }
}

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

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