Submission #1129883

#TimeUsernameProblemLanguageResultExecution timeMemory
1129883agrim_09Olympic Bus (JOI20_ho_t4)C++20
5 / 100
1096 ms9528 KiB
// #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n'; #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define py cout << "YES" << endl; #define pn cout << "NO" << endl; #define pb push_back #define int long long typedef long double lld; #define double lld typedef long long ll; typedef unsigned long long ull; const ll inf = 1e18; const ll mod = 1e9+7; const int N = 2e5; vector<int>primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; // Check for queue, priorioty_queue, stack, ordered_set solutions // stack => LIFO (whatever goes in last comes out last) // queue => FIFO (whatever goes in first comes out first) // priority_queue => Dynamic queries of minimum/maximum // ordered_set => set in vector form //[order_of_key(k) gives number of elements less than k, while find_by_order(i) gives i^th element] // To comment multiple lines : ctrl + / // To find and replace : ctrl+H void judge(){ srand(time(NULL)); #ifndef ONLINE_JUDGE freopen("inputB.txt","r",stdin); freopen("outputB.txt","w",stdout); freopen("Error.txt", "w", stderr); #define debug(x...) cerr << #x <<" = "; _print(x); cerr << endl; #else #define debug(x...) #endif } void usaco(string s) { freopen((s + ".in").c_str(),"r",stdin); freopen((s + ".out").c_str(),"w",stdout); } int dijkstra(vector<vector<pair<int,ll>>>&adj, vector<int>src){ int n = adj.size(); vector<ll>dist(n,inf); priority_queue<pair<ll,int>>pq; for(auto source : src){ dist[source] = 0; pq.push({0,source}); } while(!pq.empty()){ auto x = pq.top(); ll d = -1*x.first; int node = x.second; pq.pop(); if(d!=dist[node]){ continue; } for(auto child : adj[node]){ int v = child.first; ll w = child.second; if((d+w)<dist[v]){ dist[v] = d+w; pq.push({-1*(d+w),v}); } } } return dist[0]+dist[n-1]; } signed main(){ fastio; //judge(); int n,m; cin >> n >> m; vector<pair<int,int>> cost[n][n], invert[n][n]; vector<vector<int>>type(m); for(int i = 0,u,v,c,d;i<m;i++){ cin >> u >> v >> c >> d; u--; v--; cost[u][v].pb({c,i}); invert[u][v].pb({d,i}); type[i] = {u,v,c,d}; } // for(int i = 0;i<n;i++){ // for(int j = 0;j<n;j++){ // if(cost[i][j].size()==0){ // continue; // } // } // } int best = inf; vector<vector<int>>matrix2(n,vector<int>(n,inf)); for(int j = 0;j<m;j++){ matrix2[type[j][0]][type[j][1]] = min(matrix2[type[j][0]][type[j][1]],type[j][2]); } vector<vector<pair<int,int>>>adj2(n); for(int x = 0;x<n;x++){ for(int y = 0;y<n;y++){ if(matrix2[x][y]!=inf){ adj2[x].pb({y,matrix2[x][y]}); } } } best = min(best,dijkstra(adj2,{0}) + dijkstra(adj2,{n-1})); for(int i = 0;i<m;i++){ vector<vector<int>>matrix(n,vector<int>(n,inf)); int cost = type[i][3]; for(int j = 0;j<i;j++){ matrix[type[j][0]][type[j][1]] = min(matrix[type[j][0]][type[j][1]],type[j][2]); } for(int j = i+1;j<m;j++){ matrix[type[j][0]][type[j][1]] = min(matrix[type[j][0]][type[j][1]],type[j][2]); } matrix[type[i][1]][type[i][0]] = min(matrix[type[i][1]][type[i][0]],type[i][2]); vector<vector<pair<int,int>>>adj(n); for(int x = 0;x<n;x++){ for(int y = 0;y<n;y++){ if(matrix[x][y]!=inf){ adj[x].pb({y,matrix[x][y]}); } } } best = min(best,cost+dijkstra(adj,{0})+dijkstra(adj,{n-1})); // if(i==1){ // cout << dijkstra(adj,{0}) << endl; // } } if(best==inf){ cout << -1; } else{ cout << best; } }

Compilation message (stderr)

ho_t4.cpp: In function 'void judge()':
ho_t4.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("inputB.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("outputB.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     freopen("Error.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp: In function 'void usaco(std::string)':
ho_t4.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen((s + ".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t4.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen((s + ".out").c_str(),"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...