제출 #336546

#제출 시각아이디문제언어결과실행 시간메모리
336546GalebickosikasaCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
848 ms30680 KiB
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx") // #pragma comment(linker, "/stack:200000000"] #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <unordered_set> #include <unordered_map> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <stack> #include <random> #include <fstream> #include <sstream> #include <chrono> #define fi first #define se second #define pb push_back #define ll long long #define ld long double #define hm unordered_map #define pii pair<int, int> #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define cinv(v) for (auto& x: v) cin >> x #define fr(i, n) for (int i = 0; i < n; ++i) #define fl(i, l, n) for (int i = l; i < n; ++i) #define int ll template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;} template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;} using namespace std; #ifdef LOCAL #define dbg(x) cerr << #x << " : " << x << '\n' const int maxn = 20; #else #define dbg(x) const int maxn = 1e5 + 20; #endif //tg: @galebickosikasa ostream& operator << (ostream& out, const pii& v) { out << v.fi << ", " << v.se; return out; } template<typename T> ostream& operator << (ostream& out, const vector<T>& v) { for (auto& x: v) out << x << " "; return out; } istream& operator >> (istream& in, pii& a) { in >> a.fi >> a.se; return in; } const ll inf = (ll) 1e18; const ld pi = asin (1) * 2; const ld eps = 1e-8; const ll mod = (ll)1e9 + 7; const ll ns = 97; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); vector<pii> g[maxn]; vector<int> G[maxn]; int dp[maxn], used[maxn]; vector<int> Dijkstra (int s, int n) { vector<int> d (n, inf); d[s] = 0; set <pii> a; a.insert ({0, s}); while (!a.empty ()) { int v = a.begin ()->se; a.erase (a.begin ()); for (auto& u: g[v]) { if (d[u.fi] > d[v] + u.se) { a.erase ({d[u.fi], u.fi}); d[u.fi] = d[v] + u.se; a.insert ({d[u.fi], u.fi}); } } } return d; } void calc (int v, vector<int>& d) { used[v] = 1; dp[v] = d[v]; for (auto& u: G[v]) { if (!used[u]) calc (u, d); chkmin (dp[v], dp[u]); } } signed main () { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; int s, t; cin >> s >> t; --s, --t; int u, v; cin >> u >> v; --u, --v; for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; --a, --b; g[a].pb ({b, c}); g[b].pb ({a, c}); } auto d = Dijkstra (s, n); vector<int> kek; queue<int> a; a.push (t); while (!a.empty ()) { int v = a.front (); kek.pb (v); a.pop (); for (auto& u: g[v]) { if (d[u.fi] + u.se == d[v]) { G[v].pb (u.fi); if (!used[u.fi]) { a.push (u.fi); used[u.fi] = 1; } } } } for (auto& x: kek) { dbg (x + 1); for (auto& ch: G[x]) { dbg (ch + 1); } } int ans = 1e18; { for (auto& x: used) x = 0; d = Dijkstra (u, n); chkmin (ans, d[v]); dbg (ans); for (auto& x: kek) { if (!used[x]) calc (x, d); dbg (x + 1); dbg (dp[x]); } d = Dijkstra (v, n); for (auto& x: kek) { chkmin (ans, d[x] + dp[x]); dbg (x + 1); dbg (ans); } } { swap (v, u); for (auto& x: used) x = 0; d = Dijkstra (u, n); chkmin (ans, d[v]); // dbg (ans); for (auto& x: kek) { if (!used[x]) calc (x, d); // dbg (x + 1); // dbg (dp[x]); } d = Dijkstra (v, n); for (auto& x: kek) { chkmin (ans, d[x] + dp[x]); // dbg (x + 1); // dbg (ans); } } cout << ans << '\n'; }

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

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:146:14: warning: unused variable 'ch' [-Wunused-variable]
  146 |   for (auto& ch: G[x]) {
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...