結果
問題 |
No.1320 Two Type Min Cost Cycle
|
ユーザー |
|
提出日時 | 2020-12-10 23:00:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,093 bytes |
コンパイル時間 | 995 ms |
コンパイル使用メモリ | 88,512 KB |
最終ジャッジ日時 | 2025-01-16 21:39:37 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 TLE * 43 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:13:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%d",&T); | ~~~~~^~~~~~~~~ main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d%d",&N,&M); | ~~~~~^~~~~~~~~~~~~~ main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d%d%d",&u,&v,&w); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <numeric> #include <algorithm> #include <map> using namespace std; template <class T> void chmin(T& a, const T b){a=min(a,b);} int main(void) { int T,N,M; scanf("%d",&T); scanf("%d%d",&N,&M); map<pair<int,int>,long long> edges; while(M--) { int u,v,w; scanf("%d%d%d",&u,&v,&w); u--,v--; if(T) { edges[{u,v}]=w; } else { edges[{u,v}]=edges[{v,u}]=w; } } long long inf = 1e15; long long ans = inf; vector<int> idx(N); iota(idx.begin(),idx.end(),0); do{ long long sum = 0; int root = idx.front(); for(int i=0;i<N;++i) { int u = idx[i]; int v = idx[(i+1)%N]; if(2 <= i && edges.count({u,root})) { chmin(ans,sum + edges[{u,root}]); } if(edges.count({u,v})) sum += edges[{u,v}]; else break; } } while(next_permutation(idx.begin(),idx.end())); if(ans == inf) ans = -1; printf("%lld\n",ans); }