Submission #1050614
Source Code Expand
#include<bits/stdc++.h> #define LL long long using namespace std; const int N = 400000+9; struct Edge{int u,v,w;}e[N]; struct Operation{int p,c;}op[N]; priority_queue<Operation> que; int n,m,tot,vis[N],fa[N]; LL vout; inline bool operator < (const Edge &A, const Edge &B) {return A.w < B.w;} inline bool operator < (const Operation &A, const Operation &B) {return A.c > B.c;} inline int read() { char c=getchar(); int f=1,ret=0; while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();} while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();} return ret * f; } inline int find(int w) { int f = fa[w], tmp; while (f != fa[f]) f = fa[f]; while (w != f) tmp = fa[w], fa[w] = f, w = tmp; return f; } int main() { //freopen("11input.in","r",stdin); n = read(); m = read(); for (int i=1,a,b,c;i<=m;i++) { a = read(); b = read(); c = read(); e[++tot] = (Edge){a, b, c}; que.push((Operation){a, c+1}); que.push((Operation){b, c+2}); } while (!que.empty()) { Operation w = que.top(); que.pop(); if (!vis[w.p]) { vis[w.p] = 1; e[++tot] = (Edge){w.p, (w.p+1)%n, w.c}; que.push((Operation){(w.p+1)%n, w.c+2}); } } sort(e+1, e+1+tot); for (int i=0;i<=n;i++) fa[i] = i; for (int i=1;i<=tot;i++) { if (find(e[i].u) != find(e[i].v)) { fa[fa[e[i].u]] = fa[e[i].v]; vout += e[i].w; } } printf("%lld\n",vout); return 0; }
Submission Info
Submission Time | |
---|---|
Task | G - Zigzag MST |
User | ZYQN |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 1410 Byte |
Status | AC |
Exec Time | 183 ms |
Memory | 9708 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 | 112 ms | 6000 KB |
01-03.txt | AC | 169 ms | 9708 KB |
01-04.txt | AC | 16 ms | 4096 KB |
01-05.txt | AC | 16 ms | 4096 KB |
01-06.txt | AC | 33 ms | 4096 KB |
01-07.txt | AC | 36 ms | 4096 KB |
01-08.txt | AC | 41 ms | 4224 KB |
01-09.txt | AC | 39 ms | 4604 KB |
01-10.txt | AC | 101 ms | 7024 KB |
01-11.txt | AC | 149 ms | 7788 KB |
01-12.txt | AC | 172 ms | 9708 KB |
01-13.txt | AC | 183 ms | 9708 KB |
01-14.txt | AC | 173 ms | 9708 KB |
01-15.txt | AC | 173 ms | 9708 KB |
01-16.txt | AC | 172 ms | 9708 KB |
01-17.txt | AC | 173 ms | 9708 KB |
01-18.txt | AC | 106 ms | 9708 KB |
01-19.txt | AC | 17 ms | 4096 KB |
01-20.txt | AC | 30 ms | 4224 KB |
01-21.txt | AC | 66 ms | 5876 KB |
01-22.txt | AC | 131 ms | 9708 KB |
01-23.txt | AC | 129 ms | 9708 KB |
01-24.txt | AC | 23 ms | 4604 KB |
01-25.txt | AC | 155 ms | 9708 KB |
01-26.txt | AC | 17 ms | 4096 KB |
01-27.txt | AC | 30 ms | 4604 KB |
01-28.txt | AC | 92 ms | 7664 KB |
01-29.txt | AC | 115 ms | 8044 KB |
01-30.txt | AC | 133 ms | 9708 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 |