結果
| 問題 | 
                            No.1320 Two Type Min Cost Cycle
                             | 
                    
| コンテスト | |
| ユーザー | 
                             vjudge1
                         | 
                    
| 提出日時 | 2025-10-02 09:58:14 | 
| 言語 | C++17(gcc12)  (gcc 12.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,371 bytes | 
| コンパイル時間 | 10,268 ms | 
| コンパイル使用メモリ | 220,060 KB | 
| 実行使用メモリ | 7,716 KB | 
| 最終ジャッジ日時 | 2025-10-02 09:58:27 | 
| 合計ジャッジ時間 | 7,697 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 WA * 21 | 
ソースコード
#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 == 1e18) ? -1 : ans);
    
    return 0;
}
            
            
            
        
            
vjudge1