結果
| 問題 | No.17 2つの地点に泊まりたい |
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2015-07-28 22:02:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,860 bytes |
| 記録 | |
| コンパイル時間 | 763 ms |
| コンパイル使用メモリ | 82,852 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 01:25:18 |
| 合計ジャッジ時間 | 1,608 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d",&s[i]);
| ~~~~~^~~~~~~~~~~~
main.cpp:36:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
36 | scanf("%d",&m);
| ~~~~~^~~~~~~~~
main.cpp:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
39 | scanf("%d%d%d",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>
typedef long long ll;
using namespace std;
#define mod 1000003
#define INF 1000000000
#define LLINF 2000000000000000000LL
#define SIZE 10000
int n,m,s[50],a,b,c;
bool kaku[50][51][51];
vector<pair<int,int> > way[50];
priority_queue<pair<pair<int,int>,pair<int,int> > > pq;
int main(){
int now,cost,fir,sec;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&s[i]);
scanf("%d",&m);
for(int j=0;j<m;j++){
scanf("%d%d%d",&a,&b,&c);
a++;
b++;
way[a].push_back({b,c});
way[b].push_back({a,c});
}
pq.push({{0,1},{0,0}});
while(pq.size()){
pair<pair<int,int>,pair<int,int> > p = pq.top();
pq.pop();
cost = p.first.first;
now = p.first.second;
fir = p.second.first;
sec = p.second.second;
if(kaku[now][fir][sec]) continue;
kaku[now][fir][sec] = true;
if(now==n && fir>0 && sec>0){
printf("%d\n",-cost);
return 0;
}
//nowに滞在しない
for(int i=0;i<way[now].size();i++){
pq.push({{cost-way[now][i].second,way[now][i].first},{fir,sec}});
}
//nowに滞在する
if(now==fir || sec>0 || now==1 || now==n) continue;
if(fir==0)
fir = now;
else
sec = now;
for(int i=0;i<way[now].size();i++){
pq.push({{cost-way[now][i].second-s[now],way[now][i].first},{fir,sec}});
}
}
cerr << "error" << endl;
return 0;
}
goodbaton