Submission #1078687

#TimeUsernameProblemLanguageResultExecution timeMemory
1078687_rain_Robot (JOI21_ho_t4)C++14
0 / 100
376 ms21256 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fixbug false void SETIO(string name = ""){ if (name=="") return; freopen((name+".inp").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); return; } const int maxn = 1e5; const int maxm = 2e5; const ll INF = (ll)1e18+7; struct _data{ ll cost; int u , color; bool operator > (const _data &other) const{ return cost > other.cost; } bool operator < (const _data &other) const{ return cost < other.cost; } }; struct Node{ int to , c , p; }; vector<Node> g[maxn+2]; ll sum[maxm+2]; bool used[maxn+2] = {}; map<pair<int,int> , bool> vis; int n , m; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); SETIO(""); cin >> n >> m; for (int i = 1; i <= m; ++i){ int u , v , c , p; cin >> u >> v >> c >> p; g[u].push_back({v , c , p}); g[v].push_back({u , c , p}); } //... build the base priority_queue<_data,vector<_data>,greater<_data>> q; ll ans = INF; q.push({0 , 1 , m + 1}); while (q.size()){ ll cost = q.top().cost; int u = q.top().u; int color = q.top().color; q.pop(); if (vis[{u , color}] == 1) continue; if (fixbug){ cout << "(DEBUG)\n"; cout << u << ' ' << color << ' ' << cost << '\n'; } vis[{u , color}] = true; if (u == n) ans = min(ans , cost); for (auto& x : g[u]) sum[x.c] += x.p; for (auto& x : g[u]){ int v = x.to , c = x.c , p = x.p; if (c == color) continue; if (!vis[{v , m + 1}]) q.push({cost + p , v , m + 1}); if (!vis[{v , c}]) q.push({cost + sum[c] - p , v , c}); if (fixbug){ cout << "(DEBUG ORZZZ)\n"; cout << u << "->" << v << ' ' << c << ' ' << sum[c] << '\n'; cout << '\n'; } } for (auto& x : g[u]) sum[x.c] -= x.p; } cout << ans; }

Compilation message (stderr)

Main.cpp: In function 'void SETIO(std::string)':
Main.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen((name+".inp").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen((name+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...