結果
問題 | No.2914 正閉路検出 |
ユーザー | GOTKAKO |
提出日時 | 2024-10-04 22:59:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,591 bytes |
コンパイル時間 | 3,071 ms |
コンパイル使用メモリ | 227,820 KB |
実行使用メモリ | 17,072 KB |
最終ジャッジ日時 | 2024-10-04 22:59:28 |
合計ジャッジ時間 | 7,719 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 1 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 9 ms
5,248 KB |
testcase_20 | AC | 18 ms
7,680 KB |
testcase_21 | AC | 6 ms
5,248 KB |
testcase_22 | AC | 23 ms
8,064 KB |
testcase_23 | AC | 16 ms
7,296 KB |
testcase_24 | AC | 24 ms
8,448 KB |
testcase_25 | AC | 3 ms
5,248 KB |
testcase_26 | AC | 5 ms
5,248 KB |
testcase_27 | AC | 28 ms
9,856 KB |
testcase_28 | AC | 37 ms
11,392 KB |
testcase_29 | AC | 71 ms
13,568 KB |
testcase_30 | AC | 11 ms
6,912 KB |
testcase_31 | AC | 28 ms
9,984 KB |
testcase_32 | AC | 38 ms
11,648 KB |
testcase_33 | AC | 10 ms
9,344 KB |
testcase_34 | AC | 87 ms
15,744 KB |
testcase_35 | AC | 81 ms
15,872 KB |
testcase_36 | AC | 95 ms
15,872 KB |
testcase_37 | AC | 51 ms
16,192 KB |
testcase_38 | AC | 39 ms
12,672 KB |
testcase_39 | AC | 91 ms
16,464 KB |
testcase_40 | AC | 115 ms
16,592 KB |
testcase_41 | AC | 91 ms
16,936 KB |
testcase_42 | AC | 86 ms
16,340 KB |
testcase_43 | AC | 86 ms
16,444 KB |
testcase_44 | AC | 104 ms
17,072 KB |
testcase_45 | AC | 92 ms
16,832 KB |
testcase_46 | AC | 85 ms
16,804 KB |
testcase_47 | AC | 90 ms
17,072 KB |
testcase_48 | AC | 95 ms
17,048 KB |
testcase_49 | AC | 93 ms
16,568 KB |
testcase_50 | AC | 98 ms
16,860 KB |
testcase_51 | AC | 40 ms
12,672 KB |
testcase_52 | AC | 41 ms
14,848 KB |
testcase_53 | WA | - |
testcase_54 | AC | 40 ms
14,848 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,M; cin >> N >> M; vector<vector<tuple<long long,long long,long long>>> Graph(N); for(long long i=0; i<M; i++){ long long u,v; cin >> u >> v; u--; v--; long long 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,long long>,vector<pair<long long,long long>>,greater<>> Q; long long start = -1; for(int i=0; i<N; i++){ if(dist.at(i) < 1e17) continue; dist.at(i) = 0; Q.push({0,i}); 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) break; } 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<long long,long long>> back(N); long long start2 = -1; vector<long long> route; vector<long long> first(N); 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; } if(start2 == -1){cout << "-1\n"; return 0;} 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(long long i=0; i<route.size(); i++){ if(i) cout << " "; cout << route.at(i)+1; } cout << endl; }