結果
| 問題 |
No.1480 Many Complete Graphs
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-24 05:48:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 139 ms / 2,000 ms |
| コード長 | 987 bytes |
| コンパイル時間 | 923 ms |
| コンパイル使用メモリ | 79,908 KB |
| 実行使用メモリ | 28,416 KB |
| 最終ジャッジ日時 | 2024-07-04 09:00:01 |
| 合計ジャッジ時間 | 7,006 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 57 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[5<<17];
long dist[5<<17];
main()
{
cin>>N>>M;
for(int i=0;i<M;i++)
{
int k,c;cin>>k>>c;
c++;
for(int j=0;j<k;j++)
{
int s;cin>>s;
s--;
G[s].push_back(make_pair(N+i*4+s%2,s/2));
G[N+i*4+2+s%2].push_back(make_pair(s,s/2));
}
G[N+i*4].push_back(make_pair(N+i*4+2,c));
G[N+i*4].push_back(make_pair(N+i*4+3,c+1));
G[N+i*4+1].push_back(make_pair(N+i*4+2,c+1));
G[N+i*4+1].push_back(make_pair(N+i*4+3,c+1));
}
for(int i=0;i<N+4*M;i++)dist[i]=9e18;
priority_queue<pair<long,int> >P;
dist[0]=0;
P.push(make_pair(0,0));
while(!P.empty())
{
int u=P.top().second;
long c=-P.top().first;
P.pop();
if(dist[u]<c)continue;
for(pair<int,int>e:G[u])
{
int v=e.first;
long nxt=c+e.second;
if(dist[v]>nxt)
{
dist[v]=nxt;
P.push(make_pair(-nxt,v));
}
}
}
long ans=dist[N-1];
if(ans==(long)9e18)ans=-1;
cout<<ans<<endl;
}