結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー vjudge1
提出日時 2025-10-02 09:56:52
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,348 bytes
コンパイル時間 9,940 ms
コンパイル使用メモリ 219,812 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-02 09:57:05
合計ジャッジ時間 12,472 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 8 WA * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;

const int N = 2e3 + 5;
int T, n, m, u, v, w, ans = 1e18, dis[N];
bool vis[N], mark[N];
struct Node {
    int v, w, id;
} ;
vector<Node> g[N];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;

inline void dijkstra(int s) {
    fill(dis + 1, dis + 1 + n, 1e18);
    dis[s] = 0;
    q.push({0ll, s});

    while(! q.empty()) {
        auto [_, u] = q.top();
        q.pop();

        if(vis[u]) continue ;

        vis[u] = true;

        for(auto [x, w, id] : g[u]) {
            if(mark[id]) continue ;

            if(dis[u] + w < dis[x]) {
                dis[x] = dis[u] + w;
                q.push({dis[x], x});
            } 
        }
    }

    return ;
}

signed main() {
    ios_base :: sync_with_stdio(NULL);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> T >> n >> m;
    for(int i = 1 ; i <= m ; ++ i) {
        cin >> u >> v >> w;

        g[u].pb({v, w, i});
        if(! T) g[v].pb({u, w, i});
    }

    for(int i = 1 ; i <= n ; ++ i)
        for(auto [j, w, id] : g[i]) {
            mark[id] = true;

            dijkstra(j);

            mark[id] = false;
            ans = min(ans, dis[i] + w);
            // cerr << "dis:" << dis[i] << '\n';
        }

    cout << ans;
    
    return 0;
}
0