結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  assy1028 | 
| 提出日時 | 2015-03-21 19:10:55 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 11 ms / 5,000 ms | 
| コード長 | 2,019 bytes | 
| コンパイル時間 | 832 ms | 
| コンパイル使用メモリ | 93,540 KB | 
| 実行使用メモリ | 6,656 KB | 
| 最終ジャッジ日時 | 2024-10-15 01:20:06 | 
| 合計ジャッジ時間 | 1,778 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:66:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
main.cpp:69:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |         scanf("%d", &s);
      |         ~~~~~^~~~~~~~~~
main.cpp:80:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~
main.cpp:83:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   83 |         scanf("%d%d%d", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
typedef unsigned long long ull;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1000000009;
const int MAX = 100*52;
struct edge {
    int to, cost;
};
vector<edge> G[MAX];
int d[MAX];
void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+MAX, inf);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
	P p = que.top(); que.pop();
	int v = p.second;
	if (d[v] < p.first) continue;
	for (int i = 0; i < G[v].size(); i++) {
	    edge e = G[v][i];
	    if (d[e.to] > d[v] + e.cost) {
		d[e.to] = d[v] + e.cost;
		que.push(P(d[e.to], e.to));
	    }
	}
    }
}
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
	int s;
	scanf("%d", &s);
	if (0 < i && i < n-1) {
	    G[i].push_back(edge{i+(2*i-1)*n, s});
	    for (int j = 1; j < n-1; j++) {
		if (j != i) {
		    G[i+(2*j-1)*n].push_back(edge{i+2*j*n, s});
		}
	    }
	}
    }
    int m;
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	for (int j = 0; j <= 2*(n-1); j++) {
	    G[a+j*n].push_back(edge{b+j*n, c});
	    G[b+j*n].push_back(edge{a+j*n, c});
	}
    }
    dijkstra(0);
    int res = inf;
    for (int i = 1; i < n-1; i++) {
	res = min(res, d[n-1+2*i*n]);
    }
    printf("%d\n", res);
}
            
            
            
        