이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sort undefined_function // To use stable_sort instead sort
#define bpc __builtin_popcount
#define ull unsigned long long
#define ld double
#define ll long long
#define mp make_pair
#define F first
#define S second
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less_equal<long long>,
rb_tree_tag, tree_order_statistics_node_update> Tree;
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MOD = 1e9 + 7; //[998244353, 1e9 + 7, 1e9 + 13]
const ld PI = acos(-1);
const ll NROOT = 500;
ll binpow(ll a, ll b, ll _MOD = -1) {
if (_MOD == -1)
_MOD = MOD;
ll res = 1;
for (; b; b /= 2, a *= a, a %= _MOD)
if (b & 1) res *= a, res %= _MOD;
return res;
}
void set_IO(string s) {
#ifndef LOCAL
string in = s + ".in";
string out = s + ".out";
freopen(in.c_str(), "r", stdin);
freopen(out.c_str(), "w", stdout);
#endif
}
bool dataOverflow(ll a, ll b) {return (log10(a) + log10(b) >= 18);}
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll ceil(ll a, ll b) {return (a + b - 1) / b;}
ll invmod(ll a) {return binpow(a, MOD - 2);}
#define int long long
int n, m;
vector<vector<pair<int, pair<int, int>>>> g;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
g.resize(n + 1);
int index = 0;
for (int i = 1; i <= m; i ++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
index = max(index, c + 1);
g[a].push_back({b, {c, d}});
g[b].push_back({a, {c, d}});
}
using T = pair<ll, int>;
priority_queue<T, vector<T>, greater<T>> q;
q.push({0, 1});
vector<ll> dis(n + 1, INF);
while (!q.empty()) {
auto [d, x] = q.top();
q.pop();
if (dis[x] <= d)
continue;
dis[x] = d;
map<int, int> f;
for (auto &y : g[x])
f[y.S.F] ++;
for (auto &y : g[x]) {
if (f[y.S.F] > 1) {
q.push({d + y.S.S, y.F});
y.S.F = ++index;
f[y.S.F] --;
}
else
q.push({d, y.F});
}
}
if (dis[n] == INF)
cout << "-1\n";
else
cout << dis[n] << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int32_t main()':
Main.cpp:87:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
87 | auto [d, x] = q.top();
| ^
Main.cpp: In function 'void set_IO(std::string)':
Main.cpp:46:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(in.c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen(out.c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |