Submission #1013584

#TimeUsernameProblemLanguageResultExecution timeMemory
1013584vjudge1timeismoney (balkan11_timeismoney)C++17
40 / 100
12 ms2320 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define MEMSET_MAX 0x7f #define testcases \ int test_amount; \ cin >> test_amount; \ while (test_amount--) const ll inf = 1e16; const int mod = 1e9+7; ll n, m, sum, x, y, t, c, tsum, csum; bool visited[203]; vector<pair<ll, pll>> adj[203]; set<pair<ll, pll>> e; pair<ll, pll> w; vector<pll> res; map<pll, bool> mp; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> x >> y >> t >> c; adj[x].push_back({t, {x, y}}); adj[y].push_back({t, {x, y}}); tsum += t; csum += c; res.push_back({x, y}); } if (m == n-1) { cout << tsum << " " << csum << "\n"; for (auto i : res) cout << i.first << " " << i.second << "\n"; return 0; } res.clear(); visited[0] = 1; for (auto i : adj[0]) {e.insert(i); mp[{i.second.first, i.second.second}] = 1;} while (!e.empty()) { w = (*e.begin()); if (visited[(*e.begin()).second.first] == 0 || visited[(*e.begin()).second.second] == 0) { sum += (*e.begin()).first; x = (*e.begin()).second.first; y = (*e.begin()).second.second; //cout << "edge " << x << " " << y << "\n"; if (!visited[x]) for (auto i : adj[x]) { //cout << i.second.first << " " << i.second.second << " " << mp[{i.second.first, i.second.second}] << "\n"; if (mp[{i.second.first, i.second.second}]) continue; e.insert(i); mp[{i.second.first, i.second.second}] = 1; } if (!visited[y]) for (auto i : adj[y]) { //cout << i.second.first << " " << i.second.second << " " << mp[{i.second.first, i.second.second}] << "\n"; if (mp[{i.second.first, i.second.second}]) continue; e.insert(i); mp[{i.second.first, i.second.second}] = 1; } visited[x] = 1; visited[y] = 1; res.push_back({x, y}); } e.erase(w); } for (auto i : e) { if (visited[i.second.first] == 0 || visited[i.second.second] == 0) { sum += i.first; visited[i.second.first] = 1; visited[i.second.second] = 1; res.push_back({i.second.first, i.second.second}); } } cout << sum << " " << sum << "\n"; for (auto i : res) cout << i.first << " " << i.second << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...