結果
| 問題 |
No.1480 Many Complete Graphs
|
| コンテスト | |
| ユーザー |
蜜蜂
|
| 提出日時 | 2021-03-04 20:09:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 400 ms / 2,000 ms |
| コード長 | 1,095 bytes |
| コンパイル時間 | 1,975 ms |
| コンパイル使用メモリ | 177,068 KB |
| 実行使用メモリ | 16,372 KB |
| 最終ジャッジ日時 | 2024-07-03 04:03:51 |
| 合計ジャッジ時間 | 9,803 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 57 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:44:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
44 | auto [now,dist] = que.top();
| ^
main.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
51 | for(auto [next,dist2] : graph[now]){
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define pb push_back
using T = pair<int,ll>;
int main(){
int n,m;
cin>>n>>m;
vector<vector<T>> graph(n+2*m);
vector<ll> ans(n+2*m,1e18);
ans[0]=0;
for(int i=0;i<m;i++){
int k;
ll c;
cin>>k>>c;
graph[n+2*i].pb({n+2*i+1,1});
graph[n+2*i+1].pb({n+2*i,1});
for(int j=0;j<k;j++){
int s;
cin>>s;
if(s%2==1){
graph[s-1].pb({n+2*i,s+c});
graph[n+2*i].pb({s-1,s+c});
}
else{
graph[s-1].pb({n+2*i+1,s+c});
graph[n+2*i+1].pb({s-1,s+c});
}
}
}
priority_queue<T,vector<T>,greater<T>> que;
que.push({0,0});
while(!que.empty()){
auto [now,dist] = que.top();
que.pop();
if(dist>ans[now]){
continue;
}
for(auto [next,dist2] : graph[now]){
if(ans[now]+dist2<ans[next]){
que.push({next,dist2});
ans[next]=ans[now]+dist2;
}
}
}
if(ans[n-1]>=1e18){
ans[n-1]=-2;
}
cout<<ans[n-1]/2<<endl;
}
蜜蜂