제출 #770355

#제출 시각아이디문제언어결과실행 시간메모리
770355mgl_diamondRobot (JOI21_ho_t4)C++17
100 / 100
763 ms81004 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; #define foru(i, l, r) for(int i=(l); i<=(r); ++i) #define ford(i, l, r) for(int i=(l); i>=(r); --i) #define fore(x, v) for(auto &x : v) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define fi first #define se second void setIO(string name) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (!name.empty()) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } const ll LINF = 1e15; const int N = 1e5+5; const int M = 2e5+5; int n, m; map<int, vector<ii>> graph[N]; ll dp[N]; map<int, ll> dp2[N], sum[N]; int main() { setIO(""); cin >> n >> m; foru(i, 1, m) { int u, v, c, p; cin >> u >> v >> c >> p; graph[u][c].emplace_back(v, p); graph[v][c].emplace_back(u, p); sum[u][c] += p; sum[v][c] += p; } memset(dp, 0x3f, sizeof(dp)); priority_queue<pair<ll, ii>> pq; dp[1] = 0; pq.push({0, {1, 0}}); while (!pq.empty()) { auto top = pq.top(); pq.pop(); ll cost = top.fi; int u = top.se.fi, c = top.se.se; if (!c) { if (-cost != dp[u]) continue; fore(nc, graph[u]) fore(info, nc.se) { int v = info.fi, p = info.se; ll ncost; ncost = sum[u][nc.fi] - p - cost; if (ncost < dp[v]) { dp[v] = ncost; pq.push({-ncost, {v, 0}}); } ncost = p - cost; if (ncost < dp[v]) { dp[v] = ncost; pq.push({-ncost, {v, 0}}); } ncost = -cost; if ((dp2[v].find(nc.fi) == dp2[v].end()) || ncost < dp2[v][nc.fi]) { dp2[v][nc.fi] = ncost; pq.push({-ncost, {v, nc.fi}}); } } } else { if (-cost != dp2[u][c]) continue; ll ncost = sum[u][c] - cost; fore(info, graph[u][c]) { int v = info.fi, p = info.se; if (ncost - p < dp[v]) { dp[v] = ncost - p; pq.push({-ncost + p, {v, 0}}); } } } } cout << (dp[n] < LINF ? dp[n] : -1); }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen((name + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     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...