結果
| 問題 | No.807 umg tours |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-05-20 13:12:03 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 426 ms / 4,000 ms |
| コード長 | 1,642 bytes |
| 記録 | |
| コンパイル時間 | 886 ms |
| コンパイル使用メモリ | 151,672 KB |
| 実行使用メモリ | 30,708 KB |
| 最終ジャッジ日時 | 2026-04-26 09:57:39 |
| 合計ジャッジ時間 | 10,163 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
main.cpp:59:12: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
59 | ll costs[N + 1][2];
| ^~~~~
main.cpp:59:12: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:47:7: note: declared here
47 | int N, M;
| ^
main.cpp:61:16: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
61 | bool visited[N + 1][2];
| ^~~~~
main.cpp:61:16: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:47:7: note: declared here
47 | int N, M;
| ^
2 warnings generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
const int MAX_N = 100010;
struct Edge {
int to;
ll cost;
Edge(int to = -1, ll cost = -1) {
this->to = to;
this->cost = cost;
}
};
struct Node {
int v;
ll cost;
bool use_ticket;
Node(int v = -1, ll cost = -1, bool use_ticket = false) {
this->v = v;
this->cost = cost;
this->use_ticket = use_ticket;
}
bool operator>(const Node &n) const {
return cost > n.cost;
}
};
vector<Edge> E[MAX_N];
int main() {
int N, M;
cin >> N >> M;
int a, b, c;
for (int i = 0; i < M; ++i) {
cin >> a >> b >> c;
E[a].push_back(Edge(b, c));
E[b].push_back(Edge(a, c));
}
priority_queue <Node, vector<Node>, greater<Node>> pque;
pque.push(Node(1, 0));
ll costs[N + 1][2];
memset(costs, 0, sizeof(costs));
bool visited[N + 1][2];
memset(visited, false, sizeof(visited));
costs[1][1] = 0;
visited[1][1] = true;
while (not pque.empty()) {
Node node = pque.top();
pque.pop();
if (visited[node.v][node.use_ticket]) continue;
visited[node.v][node.use_ticket] = true;
costs[node.v][node.use_ticket] = node.cost;
for (auto &[u, cost] : E[node.v]) {
pque.push(Node(u, node.cost + cost, node.use_ticket));
if (not node.use_ticket) {
pque.push(Node(u, node.cost, true));
}
}
}
for (int i = 1; i <= N; ++i) {
cout << costs[i][0] + costs[i][1] << endl;
}
return 0;
}
siman