Submission #479972

#TimeUsernameProblemLanguageResultExecution timeMemory
479972YuisuyunoRobot (JOI21_ho_t4)C++14
100 / 100
1053 ms87644 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 to, c, 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.to]){ d[i.to] = case1; q.push({-d[i.to],i.to,0}); } } } else { if (d[node] != -cost) continue; for (auto& i : g[node]) { for (edge j : i.second) { // Case 1: We don't flip j int case1 = psum[node][j.c] - j.p - cost; if (case1 < d[j.to]) { d[j.to] = case1; q.push({-d[j.to], j.to, 0}); } // Case 2: We flip j but not another edge of the same colour int case2 = j.p - cost; if (case2 < d[j.to]) { d[j.to] = case2; q.push({-d[j.to], j.to, 0}); } // Case 3: We flip j and another edge of the same colour int case3 = -cost; if (!d2[j.to].count(j.c) || case3 < d2[j.to][j.c]) { d2[j.to][j.c] = case3; q.push({-d2[j.to][j.c], j.to, j.c}); } } } } } 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...