Submission #992576
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> PII; #define fi first #define se second #define mp make_pair #define pb push_back #define N 400010 int n, m; int f[N]; int px[N], py[N], pz[N]; set<PII> A; int fa(int x) { if (f[x] == x) return x; f[x] = fa(f[x]); return f[x]; } int main() { cin >> n >> m; for (int i = 0; i < m; i ++) { cin >> px[i] >> py[i] >> pz[i]; A.insert(mp(pz[i], i)); px[i+m] = py[i]; py[i+m] = (px[i]+1)%n; pz[i+m] = pz[i]+1; A.insert(mp(pz[i]+1, i+m)); } for (int i = 0; i < n; i ++) f[i] = i; ll S = 0; while (!A.empty()) { PII _x = *A.begin(); A.erase(A.begin()); int i = _x.se; int z = _x.fi; int x = px[i]; int y = py[i]; if (fa(x) != fa(y)) { S += z; f[fa(x)] = fa(y); (px[i] += 1) %= n; (py[i] += 1) %= n; A.insert(mp(z+2, i)); } } cout << S << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | G - Zigzag MST |
User | sevenkplus |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 944 Byte |
Status | AC |
Exec Time | 452 ms |
Memory | 27648 KB |
Judge Result
Set Name | sample | all | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 3 ms | 256 KB |
01-02.txt | AC | 337 ms | 23680 KB |
01-03.txt | AC | 422 ms | 24704 KB |
01-04.txt | AC | 18 ms | 3328 KB |
01-05.txt | AC | 18 ms | 2048 KB |
01-06.txt | AC | 21 ms | 1664 KB |
01-07.txt | AC | 22 ms | 1280 KB |
01-08.txt | AC | 27 ms | 1280 KB |
01-09.txt | AC | 55 ms | 2304 KB |
01-10.txt | AC | 237 ms | 12800 KB |
01-11.txt | AC | 426 ms | 24064 KB |
01-12.txt | AC | 445 ms | 24448 KB |
01-13.txt | AC | 446 ms | 24448 KB |
01-14.txt | AC | 444 ms | 24448 KB |
01-15.txt | AC | 447 ms | 24448 KB |
01-16.txt | AC | 442 ms | 24448 KB |
01-17.txt | AC | 452 ms | 24448 KB |
01-18.txt | AC | 394 ms | 27648 KB |
01-19.txt | AC | 20 ms | 1280 KB |
01-20.txt | AC | 41 ms | 1280 KB |
01-21.txt | AC | 145 ms | 7808 KB |
01-22.txt | AC | 420 ms | 24448 KB |
01-23.txt | AC | 419 ms | 24448 KB |
01-24.txt | AC | 39 ms | 5632 KB |
01-25.txt | AC | 408 ms | 27520 KB |
01-26.txt | AC | 19 ms | 4096 KB |
01-27.txt | AC | 52 ms | 2176 KB |
01-28.txt | AC | 262 ms | 15488 KB |
01-29.txt | AC | 376 ms | 24064 KB |
01-30.txt | AC | 407 ms | 24448 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |
sample-03.txt | AC | 3 ms | 256 KB |