제출 #92133

#제출 시각아이디문제언어결과실행 시간메모리
92133karmaCommuter Pass (JOI18_commuter_pass)C++11
0 / 100
2063 ms2808 KiB
#include<bits/stdc++.h> #define For(i, a, b) for(int i = a, _b = b; i <= _b; ++i) #define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i) #define FileName "test" #define ll long long #define ld long double #define ull unsigned long long #define Print(x) cerr << #x << "is " << x << '\n'; #define pb push_back #define X first #define Y second #define Karma using namespace std; template<typename T> inline void Cin(T &x) { char c; T sign = 1; x = 0; for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -1; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sign; } template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');} template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);} template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);} template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);} typedef pair<int, int> pii; typedef pair<ll, int> plli; const int N = 1e5 + 7; const ll oo = (ll)1e18 + 7; struct TEdge { int u, v; ll w; } _e[N * 2]; typedef TEdge* PEdge; PEdge e; ll dis[N]; bitset<N> Q; queue<int> q; vector<ll> d[2]; vector<PEdge> a[N]; int n, m, s, t, u, v; priority_queue<plli, vector<plli>, greater<plli>> pq; void Dijkstra(int s, vector<ll>& d) { d.resize(n + 1); for(int i = 0; i <= n; ++i) d[i] = oo; pq.push({0, s}); d[s] = 0; while(!pq.empty()) { plli top = pq.top(); pq.pop(); if(d[top.Y] != top.X) continue; int u = top.Y; for(PEdge e: a[u]) { int v = e -> u + e -> v - u; if(d[v] > d[u] + e -> w) d[v] = d[u] + e -> w, pq.push({d[v], v}); } } } void Enter() { Cin(n, m, s, t, u, v); e = _e; For(i, 1, m) { ++e; Cin(e -> u, e -> v, e -> w); a[e -> u].pb(e), a[e -> v].pb(e); } Dijkstra(s, d[0]), Dijkstra(t, d[1]); } void Solve() { fill_n(dis, n + 1, oo); dis[u] = 0; Q.set(u); q.push(u); while(!q.empty()) { int x = q.front(); q.pop(); Q.set(x, 0); for(PEdge e: a[x]) { int y = e -> u + e -> v - x; if(d[0][x] + d[1][y] + e -> w == d[0][t]) { if(dis[y] > dis[x]) { dis[y] = dis[x]; if(!Q.test(y)) Q.set(y), q.push(y); } } else if(dis[y] > dis[x] + e -> w) { dis[y] = dis[x] + e -> w; if(!Q.test(y)) Q.set(y), q.push(y); } } } cout << dis[v]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef Karma freopen(FileName".inp", "r", stdin); freopen(FileName".out", "w", stdout); #endif // Karma Enter(); Solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:121:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FileName".inp", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:122:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FileName".out", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...