Submission #693121

#TimeUsernameProblemLanguageResultExecution timeMemory
693121guagua0407Robot (JOI21_ho_t4)C++17
34 / 100
3088 ms61340 KiB
/* 我是不是要給自己設定一個想題目的時間 hard - 50 分鐘 medium - 30 分鐘 easy - 15 分鐘 */ #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll,ll> #define f first #define s second #define all(x) x.begin(),x.end() #define sz(x) (ll)(x.size()) #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const ll mxn=1e5+5; vector<pair<ll,pair<ll,ll>>> adj[mxn]; unordered_map<ll,ll> csum[mxn]; ll ans[mxn]; unordered_map<ll,ll> ans2[mxn]; int main() {_ //setIO("wayne"); // 1. change edge // 2. change other edges // 3. change edge and leave next node by edge with same color ll n,m; cin>>n>>m; for(ll i=0;i<m;i++){ ll a,b,c,w; cin>>a>>b>>c>>w; adj[a].push_back({b,{c,w}}); adj[b].push_back({a,{c,w}}); csum[a][c]+=w; csum[b][c]+=w; } //{-cost,node,color(if case3)} priority_queue<pair<ll,pair<ll,ll>>> pq; pq.push({0,{1,0}}); for(ll i=1;i<=n;i++) ans[i]=(ll)(1e18); ans[1]=0; while(!pq.empty()){ ll val; ll v,c; auto tmp=pq.top(); pq.pop(); val=tmp.f*-1; v=tmp.s.f; c=tmp.s.s; if(v==n and c==0){ cout<<val; return 0; } if(c){ if(ans2[v][c]!=val) continue; for(auto u:adj[v]){ if(u.s.f!=c) continue; ll res=val+csum[v][c]-u.s.s; if(res<ans[u.f]){ ans[u.f]=res; pq.push({-ans[u.f],{u.f,0}}); } } } else{ if(ans[v]!=val) continue; for(auto u:adj[v]){ ll val1=val+u.s.s; if(val1<ans[u.f]){ ans[u.f]=val1; pq.push({-ans[u.f],{u.f,0}}); } ll val2=val+csum[v][u.s.f]-u.s.s; if(val2<ans[u.f]){ ans[u.f]=val2; pq.push({-ans[u.f],{u.f,0}}); } ll val3=val; if(ans2[u.f].count(u.s.f)==0 or val3<ans2[u.f][c]){ ans2[u.f][u.s.f]=val3; pq.push({-ans2[u.f][u.s.f],{u.f,u.s.f}}); } } } } cout<<-1; return 0; } //maybe its multiset not set

Compilation message (stderr)

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...