제출 #479824

#제출 시각아이디문제언어결과실행 시간메모리
479824YuisuyunoCommuter Pass (JOI18_commuter_pass)C++14
40 / 100
615 ms27912 KiB
//Nguyen Huu Hoang Minh #include <bits/stdc++.h> #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define reset(x) memset(x, 0,sizeof(x)) #define pb push_back #define mp make_pair #define fi first #define se second #define N 100005 #define remain(x) if (x > MOD) x -= MOD #define ii pair<int, int> #define iiii pair< ii , ii > #define viiii vector< iiii > #define vi vector<int> #define vii vector< ii > #define bit(x, i) (((x) >> (i)) & 1) #define Task "test" #define int long long using namespace std; typedef long double ld; const int inf = 1e17; const int minf = -1e10; int n, m; int s, t, u, v; vector<ii> g[N]; int ds[N], dv[N], du[N]; bool vst[N]; int ans; int dp[2][N]; void readfile() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); if (fopen(Task".inp","r")) { freopen(Task".inp","r",stdin); //freopen(Task".out","w",stdout); } cin >> n >> m >> s >> t >> u >> v; for(int i=1; i<=m; i++){ int u, v, z; cin >> u >> v >> z; g[u].pb(ii(v,z)); g[v].pb(ii(u,z)); } } void djk(int st, int d[]){ fill(vst, vst+100000, false); priority_queue<ii, vii, greater<ii>> q; q.push({0,st}); while (q.size()){ int u = q.top().se; int du = q.top().fi; q.pop(); if (!vst[u]){ vst[u] = 1; d[u] = du; for(auto &i : g[u]) q.push(ii(du+i.se,i.fi)); } } } void djk2(int st, int en){ fill(vst, vst+100000, false); fill(dp[0], dp[0]+100000, inf); fill(dp[1], dp[1]+100000, inf); priority_queue<pair<int,pair<int,int>>> q; q.push({0,{st,0}}); while (q.size()){ int u, c, par; ii temp; tie(c,temp) = q.top(); tie(u,par) = temp; q.pop(); if (!vst[u]){ vst[u] = 1; ds[u] = -c; dp[0][u] = min(dp[0][par],du[u]); dp[1][u] = min(dp[1][par],dv[u]); for(auto &i : g[u]) q.push({c-i.se,{i.fi,u}}); } else if (-c == ds[u]){ int tmp1 = min(dp[0][par],du[u]); int tmp2 = min(dp[1][par],dv[u]); if (tmp1 + tmp2 < dp[0][u]+dp[1][u]){ dp[0][u] = tmp1; dp[1][u] = tmp2; } } } ans = min(ans,dp[0][en]+dp[1][en]); } void proc() { djk(u,du); djk(v,dv); ans = du[v]; djk2(s,t); djk2(t,s); cout << ans; } signed main() { readfile(); proc(); return 0; }

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

commuter_pass.cpp: In function 'void readfile()':
commuter_pass.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(Task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...