Submission #1269672

#TimeUsernameProblemLanguageResultExecution timeMemory
1269672bnd2100Robot (JOI21_ho_t4)C++20
100 / 100
154 ms21660 KiB
/* * @Author: Twynzz * @Last Modified by: Twynzz * @Note For This Problem: https://wbd.ms/share/v2/aHR0cHM6Ly93aGl0ZWJvYXJkLm1pY3Jvc29mdC5jb20vYXBpL3YxLjAvd2hpdGVib2FyZHMvcmVkZWVtLzM3MDM5NDkwNGRkNDQ1NTc5Y2Y3NWFhNjI3ZmMxOGIyX0JCQTcxNzYyLTEyRTAtNDJFMS1CMzI0LTVCMTMxRjQyNEUzRF9iZmM4ZDc5MC05ZTEwLTQ4MGEtYjliYy04OGRhZDVhNTJlZWQ= */ #include <bits/stdc++.h> using namespace std; // ------------ Define ------------ #define el "\n" #define int long long #define ld long double #define str string #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);} #define IOS {std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} #define _TBN_ signed main() #define setp(n) setprecision(n)<< fixed #define fi first #define se second #define ii pair<int,int> #define gcd(a,b) __gcd(a,b) #define iii tuple<int, int, int> #define pb push_back #define pf push_front #define eb emplace_back #define sz(v) (int)v.size() const int maxn = 1e6+9; const long long oo = 1e18; const int MOD = 1e9+7, Mod = 1e9+9; const int base = 311, base2 = 293; template<class X> bool maximize(X &a, const X &b) { if (a<b) { a = b; return 1; } return 0; } template<class X> bool minimize(X &a, const X &b) { if (a>b) { a = b; return 1; } return 0; } namespace sub1 { bool checkSub1(); void sub1(); } namespace sub2 { bool checkSub2(); void sub2(); } namespace sub3 { bool checkSub3(); void sub3(); } int lcm(int a, int b) { return a/gcd(a,b)*b; } int sqr(int x) {return x*x;} inline bool MASK(int mask, int bit) {return ((mask>>bit)&1);} inline long long F(int n) {return n*(n+1)/2;} inline void add(int &a, int b, int m = MOD) { (a += b) %= m; if (a >= m) a -= m; } inline void sub(int &a, int b, int m = MOD) { (a -= b) %= m; if (a < 0) a += m; } inline void mul(int &a, int b, int m = MOD) { a %= m, b %= m; (a *= b) %= m; } int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; // ------------ Code ------------ struct edge { int v, c, p; edge() { v = c = p = 0; } edge(int v, int c, int p) : v(v), c(c), p(p) {} }; int n, m; vector<edge> adj[maxn]; int dis[maxn], other_change[maxn], sum[maxn]; bool vis[maxn]; void dijk() { priority_queue<ii, vector<ii>, greater<ii>> q; fill(dis + 1, dis + 1 + n, oo); dis[1] = 0; q.emplace(0, 1); while(!q.empty()) { int u = q.top().se; q.pop(); if (vis[u]) continue; vis[u] = 1; for(edge e : adj[u]) { sum[e.c] = 0; other_change[e.c] = oo; } for(edge e : adj[u]) sum[e.c] += e.p; for(edge e : adj[u]) minimize(other_change[e.c], dis[e.v]); // Co ba truong hop: // - Doi mau canh u--v: dis[u] + p // - Doi mau cac canh khac, giu lai canh u--v: dis[u] + sum[c] - p // - Doi mau cac canh khac, giu lai canh u--v nhung gian tiep // giup canh x--u co the di duoc, tuc x-->u-->v co canh x--u da // duoc doi sang mau unique ko trung voi mau u--v: // dis[x] + sum[c] - p (lay min moi x ke u neu x--v cung mau u--v) for(edge e : adj[u]) { int v = e.v, c = e.c, p = e.p; int x = min({dis[u] + p, dis[u] + sum[c] - p, other_change[c] + sum[c] - p}); if (minimize(dis[v], x)) q.emplace(dis[v], v); } } } _TBN_ { IOS; if (fopen("WSHIPPER.inp","r")) file("WSHIPPER"); cin >>n >>m; for(int i = 1; i <= m; i++) { int a, b, c, p; cin >>a >>b >>c >>p; adj[a].eb(b, c, p); adj[b].eb(a, c, p); } for(int i = 1; i <= 1; i++) { if (sub1::checkSub1()) {sub1::sub1(); continue;} // if (sub2::checkSub2()) {sub2::sub2(); continue;} // if (sub3::checkSub3()) {sub3::sub3(); continue;} } return 0; } namespace sub1 { bool checkSub1() { return 1; } void sub1() { dijk(); if (dis[n] == oo) cout<< -1<< el; else cout<< dis[n]<< el; } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:17:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:156:36: note: in expansion of macro 'file'
  156 |     if (fopen("WSHIPPER.inp","r")) file("WSHIPPER");
      |                                    ^~~~
Main.cpp:17:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:156:36: note: in expansion of macro 'file'
  156 |     if (fopen("WSHIPPER.inp","r")) file("WSHIPPER");
      |                                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...