이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/* #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
// using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned ll;
template<typename T> using vt = vector<T>;
using vi = vt<int>;
using vvi = vt<vi>;
using ii = pair<int, int>;
using vii = vt<ii>;
/* template<typename T>
using indexed_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */
/* struct chash {
static ull hash_f(ull x) {x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
size_t operator()(ull x) const {static const ull RANDOM = chrono::steady_clock::now().time_since_epoch().count();return hash_f(x + RANDOM);}
};
struct iihash {
template <class T1, class T2>
size_t operator () (const pair<T1,T2> &p) const {auto h1 = hash<T1>{}(p.first);auto h2 = hash<T2>{}(p.second);return h1 ^ h2;}
};
template<class T1, class T2, class T3> using ii_umap = gp_hash_table<pair<T1,T2>,T3,iihash>;
template<class T1, class T2> using f_umap = gp_hash_table<T1,T2,chash>;
template<class T1, class T2> using o_umap = gp_hash_table<T1,T2>; */
#define sqr(x) (x)*(x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define debug(x) cerr << #x << " -> " << x << '\n'
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int inf = 1e9 + 7;
const ll infll = 1e18 + 10;
template <typename T> inline T fgcd(T a, T b) {while(b) swap(b, a %= b); return a;}
ll fpow(ll a, ll b) {ll o = 1; for(;b;b >>= 1) {if(b & 1) o = o * a;a = a * a;} return o;}
ll fpow(ll a, ll b, ll m) {ll o = 1; a %= m; for(;b;b >>= 1) {if(b & 1) o = o * a % m;a = a * a % m;} return o;}
template<class T> void uniq(vt<T> &a) {sort(all(a));a.resize(unique(all(a)) - a.begin());}
using iii = pair<int, pair<ii, int>>;
using pli = pair<pair<ll, ll>, pair<ii, int>>;
int n,m,x,y,c,p,pos,l;
ll ans = -1,du,e;
int main() {
scanf("%d%d", &n, &m);
vt<map<int, ll>> price(n + 1);
vt<vt<bitset<200001>>> visEdge(n + 1, vt<bitset<200001>>(2));
vt<vt<iii>> a(n + 1);
for(int i = 1; i <= m; i++) {
scanf("%d%d%d%d", &x, &y, &c, &p);
price[x][c] += p;
price[y][c] += p;
a[x].eb(y, mp(mp(c, p), i));
a[y].eb(x, mp(mp(c, p), i));
}
priority_queue<pli, vt<pli>, greater<pli>> pq;
pq.push({{0, 0}, mp(mp(1, 0), 0)});
while(!pq.empty()) {
p = pq.top().S.S;
tie(x, c) = pq.top().S.F;
tie(du, e) = pq.top().F;
pq.pop();
/* debug(x);
debug(c);
debug(du); */
if(visEdge[x][c != 0][p]) continue;
if(x == n) {
ans = du;
break;
}
visEdge[x][c != 0][p] = 1;
for(auto v : a[x]) {
if(v.F != 1) {
pos = v.S.S;
tie(y, l) = v.S.F;
ll k = price[x][y] - (c == y ? e : 0) - l;
/* debug(x);
debug(k);
debug(price[x][v.S.F]);
debug(c);
debug(v.F);
debug(v.S.F);
debug(v.S.S); */
pq.push({{du + k, 0}, mp(mp(v.F, 0), 0)});
pq.push({{du + l, l}, mp(mp(v.F, y), pos)});
}
}
}
printf("%lld", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d%d%d%d", &x, &y, &c, &p);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |