signedmain() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); // cerr<<(&en-&st)/1024.0/1024.0<<endl; cin >> n >> m; for (int i = 1; i <= n; i++) fa[i] = i; for (int i = 1; i <= m; i++) { int u, v, w; cin >> u >> v >> w; g[u].pb({u, v, w, i, w}); g[v].pb({v, u, w, i, w}); if (u == 1 || v == 1) q.push({1, max(u, v), w, i, w}); } while (!q.empty()) { edge tmp = q.top(); q.pop(); if (get(tmp.u) == get(tmp.v)) continue; merge(tmp.u, tmp.v); cout << tmp.id << ' '; for (auto x : g[tmp.v]) { x.len += tmp.len; q.push(x); } } return0; }
// Problem: F - Bread // Contest: AtCoder - AtCoder Beginner Contest 252 // URL: https://atcoder.jp/contests/abc252/tasks/abc252_f // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org)
/* Name: Author: xiaruize Date: */ #include<bits/stdc++.h> usingnamespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define debug(x) cerr << #x << ": " << x << endl #define double long double constint INF = 0x3f3f3f3f; constint MOD = 1000000007; constint N = 1e5 + 10;
// bool st; int n, k; priority_queue<int, vector<int>, greater<int>> q; int res = 0; // bool en;
signedmain() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); // cerr<<(&en-&st)/1024.0/1024.0<<endl; cin >> n >> k; for (int i = 1; i <= n; i++) { int x; cin >> x; res += x; q.push(x); } if (k != res) q.push(k - res); else n--; int st = 0; res = 0; while (st < n) { int x = q.top(); q.pop(); int y = q.top(); q.pop(); res += x + y; q.push(x + y); st++; } cout << res << endl; return0; }