Submission #416833

#TimeUsernameProblemLanguageResultExecution timeMemory
416833Mamnoon_SiamWild Boar (JOI18_wild_boar)C++17
0 / 100
53 ms126020 KiB
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; using ll = long long; using vi = vector<int>; #define fi first #define se second #define all(v) begin(v), end(v) #define sz(v) (int)(v.size()) using pli = pair<ll, int>; const int N = 4004; const ll inf = 1e18; int n, m, T, L; int A[N], B[N], C[N]; vi ine[N], oute[N]; ll cost[N][N]; // cost[i][j] = shortest path from i-th directed edge to j-th directed edge ll dp[N][N]; int X[N]; ll f(int i, int prv) { ll& ret = dp[i][prv]; if(~ret) return ret; if(i == L) return ret = 0; int a = X[i], b = X[i+1]; ret = inf; for(int u : oute[a]) if((u>>1) != prv) { for(int v : ine[b]) { ret = min(ret, f(i+1, v>>1) + cost[u][v]); } } return ret; } #ifdef LOCAL #include "../debug.h" #else #define debug(...) #endif int main(int argc, char const *argv[]) { #ifdef LOCAL freopen("in", "r", stdin); #endif scanf("%d %d %d %d", &n, &m, &T, &L); for(int i = 1; i <= m; ++i) { scanf("%d %d %d", &A[2*i], &B[2*i], &C[2*i]); A[2*i+1] = B[2*i]; B[2*i+1] = A[2*i]; C[2*i+1] = C[2*i]; ine[B[2*i]].emplace_back(2*i); oute[A[2*i]].emplace_back(2*i); ine[B[2*i+1]].emplace_back(2*i+1); oute[A[2*i+1]].emplace_back(2*i+1); } for(int i = 1; i <= n; ++i) { debug(ine[i], oute[i]); } for(int i = 1; i <= L; ++i) { scanf("%d", &X[i]); } for(int src = 1; src <= 2*m; ++src) { // for(int src : {4}) { vector<bool> done(2*m+2); ll *dis = cost[src]; fill(dis+1, dis+2*m+2, inf); debug(vector<ll>(dis+1, dis+2*m+1)); dis[src] = C[src]; debug(dis[src]); priority_queue<pli, vector<pli>, less<pli>> Q; Q.emplace(dis[src], src); while(sz(Q)) { int u = Q.top().se; debug(u); Q.pop(); if(done[u]) continue; done[u] = 1; for(int v : oute[B[u]]) if((u^v)>>1) { debug(v); ll nw = dis[u] + C[v]; debug(nw); debug(dis[7]); if(nw < dis[v]) { dis[v] = nw; Q.emplace(dis[v], v); } } } debug(dis[7]); } debug(cost[4][7]); while(T--) { int p, q; scanf("%d %d", &p, &q); X[p] = q; debug(vi(X+1, X+1+L)); memset(dp, -1, sizeof dp); printf("%lld\n", f(1, 0)); } return 0; }

Compilation message (stderr)

wild_boar.cpp: In function 'int main(int, const char**)':
wild_boar.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |   scanf("%d %d %d %d", &n, &m, &T, &L);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d %d %d", &A[2*i], &B[2*i], &C[2*i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d", &X[i]);
      |     ~~~~~^~~~~~~~~~~~~
wild_boar.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     scanf("%d %d", &p, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...