Submission #445892

#TimeUsernameProblemLanguageResultExecution timeMemory
445892cpp219Robot (JOI21_ho_t4)C++14
58 / 100
3076 ms91328 KiB
#pragma GCC optimization O2 #pragma GCC optimization "unroll-loop" #pragma target ("avx2") #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 1e5 + 9; const ll Log2 = 20; const ll inf = 1e16 + 7; map<ll,ll> s[N],d[N]; map<ll,vector<LL>> g[N]; ll n,m,x,y,c,p,ans = inf; struct Node{ ll val,u,c; }; bool operator < (Node a,Node b){ return a.val > b.val; } priority_queue<Node> pq; void Add(ll u,ll c,ll val){ if (d[u][c] > val) d[u][c] = val,pq.push({val,u,c}); } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n>>m; while(m--){ cin>>x>>y>>c>>p; g[x][c].push_back({y,p}); g[y][c].push_back({x,p}); s[x][c] += p; s[y][c] += p; d[x][c] = d[y][c] = inf; } for (ll i = 1;i <= n;i++) d[i][0] = inf; d[1][0] = 0; pq.push({0,1,0}); while(!pq.empty()){ Node t = pq.top(); pq.pop(); ll u = t.u,c = t.c,val = t.val; //if (val != d[u][c]) continue; if (c){ for (auto i : g[u][c]) Add(i.fs,0,val + s[u][c] - i.sc); } else{ for (auto i : g[u]){ for (auto j : i.sc){ ll v = j.fs,L = j.sc; Add(v,0,val + L); Add(v,0,val + s[u][i.fs] - L); Add(v,i.fs,val); } } } } ans = d[n][0]; if (ans != inf) cout<<ans; else cout<<-1; }

Compilation message (stderr)

Main.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
Main.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
Main.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
Main.cpp: In function 'int main()':
Main.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...