# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1013574 | vjudge1 | timeismoney (balkan11_timeismoney) | C++17 | 3 ms | 860 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
if (m != n-1) {
for (int i = 1; i <= m; i++) {
cin >> x >> y >> t >> c;
res.push_back({x, y});
tsum += t; csum += c;
}
cout << tsum << " " << csum << "\n";
for (auto i : res) cout << i.first << " " << i.second << "\n";
return 0;
}
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}});
}
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |