Submission #1050665

#TimeUsernameProblemLanguageResultExecution timeMemory
1050665vjudge1Commuter Pass (JOI18_commuter_pass)C++98
0 / 100
336 ms114984 KiB
#include <bits/stdc++.h> // #define DEBUG 1 // #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx,mmx,tune=native") // #include <ext/pb_ds/detail/standard_policies.hpp> // #include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; // typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; /* find_by_order() order_of_key() */ void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef DEBUG #define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl; #else #define dbg(x...) #endif #define elif else if #define pb push_back #define fast cin.tie(nullptr); ios_base::sync_with_stdio(false); #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define str to_string #define sz(x) int(x.size()) #define F first #define S second #define FOR(i, a, b) for (int i=a; i < (b); i++) #define F0R(i, a) for (int i=0; i < (a); i++) #define FORd(i, a, b) for (int i = (b) - 1; i >= a; i--) #define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--) #define watch(x) cout << #x << " <---- " << x << endl mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename A, typename B> inline bool umin(A& a, B b) { if (a > b) { a = b; return true; } return false; } template<typename A, typename B> inline bool umax(A& a, B b) { if (a < b) { a = b; return true; } return false; } template<typename T> T binpow(T b, T e, T m) { T r = 1; while(e > 0) { if(e & 1) r = r * b % m; b = b * b % m; e >>= 1; } return r; } using ll = long long; using ld = long double; using ull = unsigned long long; inline ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); } const int N = 1e5 + 1; const ll mod = 1e9 + 7; const ll INF = 1e18; ll n, m, k, q; int h1[4] = {1, 0, 0, -1}; int h2[4] = {0, -1, 1, 0}; ll a[N]; bool check(int x, int y) { return (x >= 0 && y >= 0 && x < n && y < m); } int go(char c) { return c - '0'; } set<pair<ll, ll>> adj[N]; /* Problems solved, rank evolved. */ int u, v; int s, t; int p[N]; ll d[N]; map<pair<int, int>, ll> mp; void tourist() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // freopen("errors.txt", "w", stderr); // #endif cin >> n >> m; cin >> s >> t; cin >> u >> v; for(int i = 0; i < m; i++){ int f,g, c; cin >> f >> g >> c; adj[f].insert({g, c}); adj[g].insert({f, c}); mp[{f, g}] = c; mp[{g, f}] = c; } set<pair<ll, int>> pq; pq.insert({0, s}); for(int i = 1; i <= n; i++) { d[i] = INF; } p[s] = -1; d[s] = 0; while(!pq.empty()){ pair<ll, int> cur = *pq.begin(); pq.erase(cur); for(auto i : adj[cur.S]){ int to = i.F; int w = i.S; if(d[to] > d[cur.F] + w){ pq.erase({d[to], to}); d[to] = d[cur.F] + w; p[to] = cur.S; pq.insert({d[to], to}); } } } int cur = t; // map<int, int> mp2; while(p[cur] != -1){ int x = p[cur]; if(adj[x].find({cur, mp.at({x, cur})}) != adj[x].end()) { adj[x].erase(adj[x].find({cur, mp.at({x, cur})})); } if(adj[cur].find({x, mp.at({x,cur})}) != adj[cur].end()){ adj[cur].erase(adj[cur].find({x, mp.at({x,cur})})); } adj[x].insert({cur, 0}); adj[cur].insert({x, 0}); // assert((mp2.count(cur) == 0) && "cycle was found!!!"); // mp2[cur] = 1; cur = x; } pq.insert({0, s}); for(int i = 1; i <= n; i++) { d[i] = INF; } p[u] = -1; d[u] = 0; while(!pq.empty()){ pair<ll, int> cur = *pq.begin(); pq.erase(cur); for(auto i : adj[cur.S]){ int to = i.F; int w = i.S; if(d[to] > d[cur.F] + w){ pq.erase({d[to], to}); d[to] = d[cur.F] + w; p[to] = cur.S; pq.insert({d[to], to}); } } } cout << d[v] << '\n'; } /*Give me some sunshine, give me some rain, its a beatifull day-ay-ay-ay...*/ int32_t main() { fast int tt = 1; // cin >> tt; while (tt--) { tourist(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...