Submission #1103158

#TimeUsernameProblemLanguageResultExecution timeMemory
1103158EkinOnalRobot (JOI21_ho_t4)C++17
0 / 100
3089 ms2097152 KiB
//#pragma GCC optimize("O3,unroll-loops,Ofast") //#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #include <bits/stdc++.h> using namespace std; #define pb push_back #define int long long #define vi vector<int> const int mod = 1e9+7; const int INF = 1e18; void solve(){ int n,m; cin>>n>>m; vector<array<int,3>> adj[n+5]; for(int i=1;i<=m;i++){ int a,b,c,d; cin>>a>>b>>c>>d; adj[a].pb({b,c,d}); adj[b].pb({a,c,d}); } vector<vi> dp(n+2,vi(m+2,INF)); dp[1][0]=0; priority_queue<array<int,4>,vector<array<int,4>>,greater<array<int,4>>> pq; pq.push({0,1,0,0});//dist,node,newcol,par vi cnt(m+2),tot(m+2); while(pq.size()){ auto node = pq.top(); pq.pop(); for(int i=0;i<=m;i++) cnt[i]=tot[i]=0; for(auto u : adj[node[1]]){ if(u[0]!=node[3]) cnt[u[1]]++,tot[u[1]]+=u[2]; else if(node[3]) cnt[node[2]]++,tot[node[2]]+=u[2]; } for(auto u : adj[node[1]]){ if(u[0]==node[3]) continue; // nodeu degisitirp gidebilir!!(gidemez :) for(int i=1;i<=m;i++){ int c=INF; if(u[1]==i) c=tot[i]-u[2]; else c=tot[i]+u[2]; if(dp[u[0]][i] > node[0]+c ){ dp[u[0]][i] = node[0]+c; pq.push({dp[u[0]][i],u[0],i,node[1]}); } } } } int ans=INF; for(int i=1;i<=m;i++) ans=min(ans,dp[n][i]); if(ans==INF) ans=-1; cout<<ans<<endl; return; } int32_t main(/*int32_t argc, char* argv[]*/){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("dining.in", "r", stdin); // freopen("dining.out", "w", stdout); int t=1; // cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...