結果
問題 | No.1382 Travel in Mitaru city |
ユーザー |
![]() |
提出日時 | 2021-02-07 20:44:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 834 bytes |
コンパイル時間 | 2,211 ms |
コンパイル使用メモリ | 206,828 KB |
最終ジャッジ日時 | 2025-01-18 13:57:25 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 68 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf("%d %d",&a,&b); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>#include <bits/stdc++.h>using namespace std;#define rep(i,n) for (int i = 0; i < (n); ++i)#define Inf 1000000001int N,M,S,T;vector<int> p;vector<vector<int>> E;int main(){cin>>N>>M>>S>>T;S--;T--;p.resize(N);rep(i,N){cin>>p[i];}E.resize(N);rep(i,M){int a,b;scanf("%d %d",&a,&b);a--;b--;E[a].push_back(b);E[b].push_back(a);}priority_queue<pair<int,int>> Q;Q.emplace(p[S],S);int last = Inf;int ans = 0;vector<bool> visited(N,false);visited[S] = true;while(Q.size()>0){int u = Q.top().first;int v = Q.top().second;Q.pop();if(u < last){last= u;ans++;}rep(i,E[v].size()){int x = E[v][i];if(visited[x])continue;visited[x] = true;Q.emplace(p[x],x);}}cout<<ans-1<<endl;return 0;}