Submission #1050611
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,vout,fa[N]; 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=0;i<=n;i++) fa[i] = i; 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 (find(w.p) != find(w.p+1)) { fa[fa[w.p]] = fa[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("%d\n",vout); return 0; }
Submission Info
Submission Time | |
---|---|
Task | G - Zigzag MST |
User | ZYQN |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1459 Byte |
Status | WA |
Exec Time | 179 ms |
Memory | 8940 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 3 ms | 256 KB |
01-02.txt | AC | 115 ms | 6000 KB |
01-03.txt | WA | 175 ms | 8940 KB |
01-04.txt | WA | 16 ms | 3328 KB |
01-05.txt | WA | 15 ms | 3328 KB |
01-06.txt | WA | 32 ms | 3328 KB |
01-07.txt | WA | 36 ms | 3328 KB |
01-08.txt | WA | 41 ms | 3456 KB |
01-09.txt | WA | 40 ms | 3836 KB |
01-10.txt | WA | 106 ms | 6256 KB |
01-11.txt | WA | 152 ms | 7404 KB |
01-12.txt | WA | 178 ms | 8940 KB |
01-13.txt | WA | 178 ms | 8940 KB |
01-14.txt | WA | 176 ms | 8940 KB |
01-15.txt | WA | 179 ms | 8940 KB |
01-16.txt | WA | 177 ms | 8940 KB |
01-17.txt | WA | 177 ms | 8940 KB |
01-18.txt | WA | 103 ms | 8940 KB |
01-19.txt | WA | 16 ms | 3328 KB |
01-20.txt | AC | 30 ms | 3456 KB |
01-21.txt | AC | 68 ms | 5108 KB |
01-22.txt | AC | 137 ms | 8940 KB |
01-23.txt | AC | 138 ms | 8940 KB |
01-24.txt | WA | 22 ms | 3836 KB |
01-25.txt | WA | 154 ms | 8940 KB |
01-26.txt | WA | 16 ms | 3328 KB |
01-27.txt | WA | 30 ms | 3708 KB |
01-28.txt | WA | 96 ms | 6896 KB |
01-29.txt | WA | 123 ms | 7660 KB |
01-30.txt | WA | 140 ms | 8940 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 |