Submission #1292311

#TimeUsernameProblemLanguageResultExecution timeMemory
1292311HaanhtienRobot (JOI21_ho_t4)C++17
0 / 100
77 ms16256 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for(int i=(a), _b=(b); i<=_b; i++) #define FORD(i, a, b) for(int i=(a), _b=(b); i>=_b; i--) #define BIT(i, j) ((i>>j)&1) #define pb push_back #define ii pair<ll, ll> #define pii pair<ll, ii> #define all(x) x.begin(), x.end() #define fi first #define se second const ll inf = 1e18; const ll mod = 1e9+7; const ll N = 200005; const ll M = 50005; int n, m; vector <tuple <int, int, int>> adj[N]; priority_queue<ii, vector<ii>, greater<ii>> pq; ll f[N], color[N], sum[N]; void dijkstra () { fill (f + 1, f + n + 1, inf); pq.push({0, 1}); f[1] = 0; while (!pq.empty()) { auto [val, u] = pq.top(); pq.pop(); if (val != f[u]) continue; for (auto [v, c, cost] : adj[u]) { color[c]++; sum[c] += cost; } for (auto [v, c, cost] : adj[u]) { if (color[c] == 1) { if (f[v] > f[u]) { f[v] = f[u]; pq.push({f[v], v}); } } else { ll x = min(1LL * cost, sum[c] - cost); if (f[v] > f[u] + x) { f[v] = f[u] + x; pq.push({f[v], v}); } } } for (auto [v, c, cost] : adj[u]) { color[c] = 0; sum[c] = 0; } } } void solve() { cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b, c, p; cin >> a >> b >> c >> p; adj[a].emplace_back(b, c, p); adj[b].emplace_back(a, c, p); } dijkstra(); if (f[n] >= inf) cout << -1; else cout << f[n]; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "robot1" if(fopen(task".inp", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } if(fopen("task.inp", "r")) { freopen("task.INP", "r", stdin); freopen("task.OUT", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         freopen("task.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         freopen("task.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...