結果

問題 No.17 2つの地点に泊まりたい
ユーザー jupiro
提出日時 2020-07-10 20:03:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,600 bytes
コンパイル時間 1,205 ms
コンパイル使用メモリ 132,388 KB
最終ジャッジ日時 2025-01-11 17:30:55
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:80:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |         ll n; scanf("%lld", &n);
      |               ~~~~~^~~~~~~~~~~~
main.cpp:81:59: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   81 |         vector<ll> s(n); for (int i = 0; i < n; i++) scanf("%lld", &s[i]);
      |                                                      ~~~~~^~~~~~~~~~~~~~~
main.cpp:82:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |         ll m; scanf("%lld", &m);
      |               ~~~~~^~~~~~~~~~~~
main.cpp:85:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   85 |         ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<typename T>
vector<T> dijkstra_V2(int start, vector<vector<T>>& dist) {
int n = dist.size();
vector<T> res(n, INF);
queue<int> q;
q.emplace(start);
vector<bool> used(n, false);
res[0] = 0;
while (!q.empty()) {
int cur = q.front();
q.pop();
used[cur] = true;
for (int i = 0; i < n; i++) chmin(res[i], res[cur] + dist[cur][i]);
int next = -1;
T d = INF;
for (int i = 0; i < n; i++) if (!used[i]) if (chmin(d, res[i])) next = i;
if (next != -1) q.emplace(next);
}
return res;
}
void warshallFloyd(ll n, vector<vector<ll>>& d) {
for (ll k = 0; k < n; k++) {
for (ll i = 0; i < n; i++) {
if (d[i][k] == INF)
continue;
for (ll j = 0; j < n; j++) {
if (d[k][j] == INF)
continue;
chmin(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
ll n; scanf("%lld", &n);
vector<ll> s(n); for (int i = 0; i < n; i++) scanf("%lld", &s[i]);
ll m; scanf("%lld", &m);
vector<vector<ll>> d(n, vector<ll>(n, INF)); for (int i = 0; i < n; i++) d[i][i] = 0;
for (int i = 0; i < m; i++) {
ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
d[a][b] = d[b][a] = c;
}
warshallFloyd(n, d);
ll res = INF;
for (int i = 1; i < n - 1; i++) for (int j = 1; j < n - 1; j++) if (i != j) {
ll len = d[0][i] + d[i][j] + d[j][n - 1];
chmin(res, len + s[i] + s[j]);
}
cout << res << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0