結果
問題 | No.2914 正閉路検出 |
ユーザー | GOTKAKO |
提出日時 | 2024-10-04 22:46:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,277 bytes |
コンパイル時間 | 3,295 ms |
コンパイル使用メモリ | 228,600 KB |
実行使用メモリ | 14,016 KB |
最終ジャッジ日時 | 2024-10-04 22:46:11 |
合計ジャッジ時間 | 8,461 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 1 ms
6,816 KB |
testcase_13 | WA | - |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 3 ms
6,820 KB |
testcase_17 | AC | 2 ms
6,820 KB |
testcase_18 | AC | 2 ms
6,820 KB |
testcase_19 | AC | 10 ms
6,820 KB |
testcase_20 | AC | 20 ms
6,820 KB |
testcase_21 | AC | 6 ms
6,820 KB |
testcase_22 | AC | 22 ms
6,816 KB |
testcase_23 | AC | 16 ms
6,816 KB |
testcase_24 | AC | 26 ms
6,820 KB |
testcase_25 | AC | 4 ms
6,816 KB |
testcase_26 | AC | 5 ms
6,816 KB |
testcase_27 | AC | 30 ms
7,808 KB |
testcase_28 | AC | 39 ms
8,964 KB |
testcase_29 | AC | 71 ms
12,032 KB |
testcase_30 | AC | 8 ms
6,912 KB |
testcase_31 | AC | 29 ms
7,680 KB |
testcase_32 | AC | 38 ms
9,088 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 78 ms
12,800 KB |
testcase_36 | AC | 79 ms
12,800 KB |
testcase_37 | AC | 51 ms
12,540 KB |
testcase_38 | AC | 44 ms
11,008 KB |
testcase_39 | AC | 91 ms
13,612 KB |
testcase_40 | AC | 79 ms
12,800 KB |
testcase_41 | AC | 94 ms
13,616 KB |
testcase_42 | AC | 81 ms
12,544 KB |
testcase_43 | AC | 113 ms
12,800 KB |
testcase_44 | AC | 79 ms
14,016 KB |
testcase_45 | AC | 79 ms
13,052 KB |
testcase_46 | AC | 77 ms
13,184 KB |
testcase_47 | AC | 96 ms
13,496 KB |
testcase_48 | AC | 97 ms
13,832 KB |
testcase_49 | AC | 86 ms
12,800 KB |
testcase_50 | AC | 93 ms
13,360 KB |
testcase_51 | AC | 44 ms
10,880 KB |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector<vector<tuple<int,int,long long>>> Graph(N); for(int i=0; i<M; i++){ int u,v; cin >> u >> v; u--; v--; int w; cin >> w; Graph.at(u).push_back({v,i,-w}); Graph.at(v).push_back({u,i,w}); } vector<bool> already(N); vector<long long> dist(N,1e18); priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<>> Q; dist.at(0) = 0; Q.push({0,0}); int start = -1; while(Q.size()){ auto [nowd,pos] = Q.top(); Q.pop(); if(nowd != dist.at(pos)) continue; if(already.at(pos)){start = pos; break;} already.at(pos) = true; for(auto [to,epos,w] : Graph.at(pos)){ if(dist.at(to) > dist.at(pos)+w){ dist.at(to) = dist.at(pos)+w; Q.push({dist.at(to),to}); } } } if(start == -1){cout << "-1\n"; return 0;} dist.assign(N,1e18); already.assign(N,false); dist.at(start) = 0; while(Q.size()) Q.pop(); Q.push({0,start}); vector<pair<int,int>> back(N); int start2 = -1; vector<int> route; while(Q.size()){ auto [nowd,pos] = Q.top(); Q.pop(); if(dist.at(pos) != nowd) continue; already.at(pos) = true; for(auto [to,epos,w] : Graph.at(pos)){ if(dist.at(to) > nowd+w){ if(to == start && nowd+w < 0){ route.push_back({epos}); start2 = pos; break; } else if(dist.at(to) > nowd+w && already.at(to) == false){ dist.at(to) = nowd+w; Q.push({dist.at(to),to}); back.at(to) = {pos,epos}; } } } if(route.size()) break; } while(start2 != start){ route.push_back(back.at(start2).second); start2 = back.at(start2).first; } reverse(route.begin(),route.end()); cout << route.size() << endl; cout << start+1 << endl; for(int i=0; i<route.size(); i++){ if(i) cout << " "; cout << route.at(i)+1; } cout << endl; }