Submission #479973

#TimeUsernameProblemLanguageResultExecution timeMemory
479973YuisuyunoRobot (JOI21_ho_t4)C++14
100 / 100
1076 ms82596 KiB
//Nguyen Huu Hoang Minh #include <bits/stdc++.h> #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define reset(x) memset(x, 0,sizeof(x)) #define pb push_back #define mp make_pair #define fi first #define se second #define N 2005 #define remain(x) if (x > MOD) x -= MOD #define ii pair<int, int> #define iiii pair< ii , ii > #define viiii vector< iiii > #define vi vector<int> #define vii vector< ii > #define bit(x, i) (((x) >> (i)) & 1) #define Task "test" #define int long long using namespace std; typedef long double ld; const int inf = 1e10; const int minf = -1e10; int n, m; struct edge{ int v, z, p; }; map<int, vector<edge>> g[100005]; int d[100005]; map<int,int> d2[100005], psum[100005]; void readfile() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); if (fopen(Task".inp","r")) { freopen(Task".inp","r",stdin); //freopen(Task".out","w",stdout); } cin >> n >> m; for(int i=1; i<=m; i++){ int u, v, z, p; cin >> u >> v >> z >> p; g[u][z].pb({v,z,p}); g[v][z].pb({u,z,p}); psum[u][z]+=p; psum[v][z]+=p; } } void proc() { memset(d, 0x3f, sizeof d); d[1]=0; priority_queue<tuple<int,int,int>> q; q.push({0,1,0}); while (q.size()){ int cost, node, c; tie(cost,node,c) = q.top(); q.pop(); if (c){ if (d2[node][c]!=-cost) continue; for(edge i : g[node][c]){ int case1 = psum[node][c]-i.p-cost; if (case1 < d[i.v]){ d[i.v] = case1; q.push({-d[i.v],i.v,0}); } } } else{ if (d[node]!=-cost) continue; for(auto &i : g[node]){ for(auto j : i.se){ int case1 = psum[node][j.z]-j.p-cost; if (case1 < d[j.v]){ d[j.v] = case1; q.push({-d[j.v],j.v,0}); } int case2 = j.p-cost; if (case2 < d[j.v]){ d[j.v] = case2; q.push({-d[j.v],j.v,0}); } int case3 = -cost; if (!d2[j.v].count(j.z) || case3 < d2[j.v][j.z]){ d2[j.v][j.z] = case3; q.push({-d2[j.v][j.z],j.v,j.z}); } } } } } cout << (d[n] > 1e18 ? -1 : d[n]); } signed main() { readfile(); proc(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'void readfile()':
Main.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(Task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...