結果

問題 No.1480 Many Complete Graphs
ユーザー 👑 Nachia
提出日時 2021-04-16 20:46:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 1,053 ms
コンパイル使用メモリ 83,700 KB
最終ジャッジ日時 2025-01-20 19:04:09
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |   scanf("%d%d",&N,&M);
      |   ~~~~~^~~~~~~~~~~~~~
main.cpp:24:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |     int k,c; scanf("%d%d",&k,&c);
      |              ~~~~~^~~~~~~~~~~~~~
main.cpp:26:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |       int s; scanf("%d",&s);
      |              ~~~~~^~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class E> using nega_queue = priority_queue<E,vector<E>,greater<E>>;
const ll INF = 1001001001001001001;
struct Edge{ int to; ll d; };
int N,M;
vector<vector<Edge>> E;
vector<ll> D;
int main(){
scanf("%d%d",&N,&M);
E.resize(N+M);
rep(i,M){
int k,c; scanf("%d%d",&k,&c);
rep(kk,k){
int s; scanf("%d",&s);
E[s-1].push_back({N+i,s+c});
E[N+i].push_back({s-1,s+c});
}
}
D.assign(N+M,INF);
nega_queue<pair<ll,int>> Q;
D[0]=0; Q.push({0,0});
while(Q.size()){
ll d = Q.top().first;
int p = Q.top().second; Q.pop();
if(D[p]!=d) continue;
for(auto e : E[p]){
ll nxd = D[p] + e.d;
if(e.to<N) if(nxd%2==1) nxd++;
if(D[e.to]<=nxd) continue;
D[e.to] = nxd; Q.push({nxd,e.to});
}
}
if(D[N-1] == INF) printf("-1\n");
else printf("%lld\n",D[N-1]/2);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0