結果
| 問題 | No.1480 Many Complete Graphs |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-24 05:51:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 98 ms / 2,000 ms |
| コード長 | 889 bytes |
| 記録 | |
| コンパイル時間 | 716 ms |
| コンパイル使用メモリ | 80,088 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2024-07-04 09:00:06 |
| 合計ジャッジ時間 | 5,543 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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[3<<17];
long dist[3<<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*2+s%2,s+c));
G[N+i*2+s%2].push_back(make_pair(s,s+c));
}
G[N+i*2].push_back(make_pair(N+i*2+1,1));
G[N+i*2+1].push_back(make_pair(N+i*2,1));
}
for(int i=0;i<N+2*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=-2;
cout<<ans/2<<endl;
}