Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #pragma GCC target("sse4")
- #include <bits/stdc++.h>
- #define f first
- #define s second
- #define pb push_back
- #define mp make_pair
- #define ts to_string
- #define ub upper_bound
- #define lb lower_bound
- const char nl = '\n';
- using namespace std;
- using ll = long long;
- using vi = vector<ll>;
- using vl = vector<ll>;
- using pii = pair<ll, ll>;
- using pll = pair<ll, ll>;
- using str = string;
- //The following debugging code was taken from Benjamin Qi's template :)
- str ts(char c) { return str(1,c); }
- str ts(bool b) { return b ? "true" : "false"; }
- str ts(const char* s) { return (str)s; }
- str ts(str s) { return s; }
- template<class A> str ts(complex<A> c) {
- stringstream ss; ss << c; return ss.str(); }
- str ts(vector<bool> v) {
- str res = "{"; for(ll i = 0;i < (ll)v.size(); i++) res += char('0'+v[i]);
- res += "}"; return res; }
- template<size_t SZ> str ts(bitset<SZ> b) {
- str res = ""; for(ll i = 0; i < b.size(); i++) res += char('0'+b[i]);
- return res; }
- template<class A, class B> str ts(pair<A,B> p);
- template<class T> str ts(T v) {
- bool fst = 1; str res = "{";
- for (const auto& x: v) {
- if (!fst) res += ", ";
- fst = 0; res += ts(x);
- }
- res += "}"; return res;
- }
- template<class A, class B> str ts(pair<A,B> p) {
- return "("+ts(p.f)+", "+ts(p.s)+")"; }
- void DBG() { cerr << "]" << endl; }
- template<class H, class... T> void DBG(H h, T... t) {
- cerr << ts(h); if (sizeof...(t)) cerr << ", ";
- DBG(t...); }
- #ifdef LOCAL
- #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
- #else
- #define dbg(...) 69
- //freopen(".in", "r", stdin);
- //freopen(".out", "w", stdout);
- #endif
- //CODE STARTS HERE-----------------------------------------------------------------------------------------//
- const ll mxN = 1e4 + 10;
- ll n, m, t, c[mxN]; ll d[mxN]; ll p[mxN], amt[mxN];
- vector<pii> adj[mxN];
- priority_queue<pii, vector<pii>, greater<pii>> pq;
- ll dist = 0;
- signed main(){
- cin.tie(nullptr);
- ios_base::sync_with_stdio(false);
- // ifstream cin("shortcut.in");
- // ofstream cout("shortcut.out");
- cin >> n >> m >> t;
- for(ll i = 0; i < n; i++)
- cin >> c[i];
- for(ll i = 0; i < m; i++){
- ll a, b, e;
- cin >> a >> b >> e;
- a--,b--;
- adj[a].pb(mp(b,e));
- adj[b].pb(mp(a,e));
- }
- pq.push({0,0});
- memset(d,0x3f,sizeof(d));
- d[0] = 0;
- p[0] = 0;
- while(!pq.empty()){
- ll v=pq.top().s; ll dv = pq.top().f; pq.pop();
- // dbg(v, dv);
- if(dv > d[v]) continue;
- for(pii u : adj[v]){
- if(d[u.f] > dv + u.s || (d[u.f] == dv + u.s && v < p[u.f])){
- d[u.f] = dv + u.s;
- p[u.f] = v;
- pq.push({d[u.f], u.f});
- }
- }
- }
- for(ll i =0 ; i < n; i++){
- ll u = i;
- while(u != 0){
- amt[u] += c[i];
- u = p[u];
- }
- amt[0] += c[i];
- }
- for(ll i = 0; i< n; i++){
- dist += c[i] * d[i];
- }
- ll ans = 0;
- for(ll i=0 ; i < n; i++){
- ll curdist = dist- (d[i] * amt[i]) + (amt[i] * t);
- ans = max(ans, dist - curdist);
- }
- cout << ans << nl;
- }
Advertisement
Add Comment
Please, Sign In to add comment