Submission #5017727
Source Code Expand
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second using std::cin; using std::cout; using LL = long long; using pii = std::pair<int, int>; using pip = std::pair<int, pii>; const int MAXN = 2e5 + 10; int f[MAXN]; int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); } bool unite(int x, int y) { int fx = find(x), fy = find(y); if (fx == fy)return false; f[fx] = fy; return true; } void solve() { int n, m; cin >> n >> m; std::priority_queue<pip, std::vector<pip>, std::greater<>> q; for (int i = 1; i <= n; ++i) f[i] = i; for (int i = 0, A, B, C; i < m; ++i) { cin >> A >> B >> C; q.push({C, {A, B}}); } int cnt = 0; LL ans = 0; std::set<pii> S; while (cnt != n - 1) { pip p = q.top(); q.pop(); int c = p.fi, a = p.se.fi, b = p.se.se; // cout << a << " " << b <<"\n"; if (S.find({a, b}) != end(S)) continue; S.insert({a, b}); if (unite(a, b)) ans += c, cnt++; q.push({c + 1, {b, (a + 1) % n}}); } cout << ans << "\n"; } int main() { std::ios::sync_with_stdio(false); cin.tie(0); #ifdef trote freopen("../1.txt", "r", stdin); freopen("../out.txt", "w", stdout); #endif solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | G - Zigzag MST |
User | vjudge5 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1301 Byte |
Status | TLE |
Exec Time | 2113 ms |
Memory | 163056 KB |
Judge Result
Set Name | sample | all | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1300 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt, sample-03.txt |
all | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 1 ms | 256 KB |
01-02.txt | AC | 51 ms | 3444 KB |
01-03.txt | AC | 597 ms | 47216 KB |
01-04.txt | AC | 115 ms | 15104 KB |
01-05.txt | AC | 206 ms | 22528 KB |
01-06.txt | AC | 229 ms | 23552 KB |
01-07.txt | AC | 283 ms | 29312 KB |
01-08.txt | AC | 1034 ms | 62208 KB |
01-09.txt | AC | 1132 ms | 64448 KB |
01-10.txt | TLE | 2074 ms | 94196 KB |
01-11.txt | AC | 631 ms | 35568 KB |
01-12.txt | AC | 1635 ms | 76144 KB |
01-13.txt | TLE | 2109 ms | 100848 KB |
01-14.txt | TLE | 2109 ms | 101488 KB |
01-15.txt | AC | 1800 ms | 83696 KB |
01-16.txt | AC | 1578 ms | 76144 KB |
01-17.txt | AC | 1786 ms | 82032 KB |
01-18.txt | AC | 300 ms | 22128 KB |
01-19.txt | AC | 254 ms | 28288 KB |
01-20.txt | AC | 1126 ms | 69760 KB |
01-21.txt | AC | 1771 ms | 105720 KB |
01-22.txt | AC | 1596 ms | 105968 KB |
01-23.txt | AC | 1617 ms | 102512 KB |
01-24.txt | AC | 247 ms | 19904 KB |
01-25.txt | AC | 326 ms | 22128 KB |
01-26.txt | AC | 263 ms | 19840 KB |
01-27.txt | TLE | 2111 ms | 133440 KB |
01-28.txt | TLE | 2112 ms | 154740 KB |
01-29.txt | TLE | 2113 ms | 163056 KB |
01-30.txt | TLE | 2113 ms | 159728 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |
sample-03.txt | AC | 1 ms | 256 KB |