제출 #479831

#제출 시각아이디문제언어결과실행 시간메모리
479831YuisuyunoCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
567 ms31388 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; typedef int ll; const int inf = LLONG_MAX/2; 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[3][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 dijkstra1(ll start, ll arr[]) { fill(vst, vst + 100001, false); priority_queue<pair<ll, ll>> pq; pq.push({0, start}); while (!pq.empty()) { ll c, node; tie(c, node) = pq.top(); pq.pop(); if (!vst[node]) { arr[node] = -c; vst[node] = true; for (auto& i : g[node]) pq.push({c - i.second, i.first}); } } } void djk2(int st, int en){ fill(vst, vst+100001, false); fill(dp[0], dp[0]+100001, inf); fill(dp[1], dp[1]+100001, inf); priority_queue<pair<int,pair<int,int>>> q; q.push({0,{st,0}}); dp[0][0] = dp[1][0] = inf; while (q.size()){ int node, c, par; ii temp; tie(c,temp) = q.top(); tie(node,par) = temp; q.pop(); if (!vst[node]){ vst[node] = 1; ds[node] = -c; dp[0][node] = min(dp[0][par],du[node]); dp[1][node] = min(dp[1][par],dv[node]); for(auto &i : g[node]) q.push({c-i.se,{i.fi,node}}); } else if (-c == ds[node]){ int tmp1 = min(dp[0][par],du[node]); int tmp2 = min(dp[1][par],dv[node]); if (tmp1 + tmp2 < dp[0][node]+dp[1][node]){ dp[0][node] = tmp1; dp[1][node] = tmp2; } } } ans = min(ans,dp[0][en]+dp[1][en]); } void proc() { dijkstra1(u,du); dijkstra1(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:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         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...