Submission #2171834
Source Code Expand
#include<cstdio> #include<algorithm> int n,m,fa[200005],num; long long ans,d[200005]; long long min(long long a,long long b){return a<b?a:b;} struct node{int u,v;long long w;}e[400005]; int find(int u) { if(fa[u]==u)return u; return fa[u]=find(fa[u]); } bool comp(node a,node b){return a.w<b.w;} int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;i++)d[i]=1e18; for(int i=1;i<=m;i++) { int x,y;long long z; scanf("%d%d%lld",&x,&y,&z); e[++num]=(node){x,y,z}; d[x]=min(d[x],z+1); d[y]=min(d[y],z+2); } for(int t=0;t<2;t++) for(int i=0;i<n;i++) d[(i+1)%n]=min(d[i]+2,d[(i+1)%n]); for(int i=0;i<n;i++)e[++num]=(node){i,(i+1)%n,d[i]},fa[i]=i; std::sort(e+1,e+1+num,comp); int t=0; for(int i=1;i<=num;i++) if(find(e[i].u)!=find(e[i].v)) { fa[fa[e[i].u]]=fa[e[i].v]; t++;ans+=e[i].w;if(t==n-1)break; } printf("%lld\n",ans); }
Submission Info
Submission Time | |
---|---|
Task | G - Zigzag MST |
User | vjudge5 |
Language | Bash (GNU bash v4.3.11) |
Score | 0 |
Code Size | 859 Byte |
Status | RE |
Exec Time | 27 ms |
Memory | 1996 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 | RE | 27 ms | 1996 KB |
01-02.txt | RE | 3 ms | 532 KB |
01-03.txt | RE | 3 ms | 532 KB |
01-04.txt | RE | 3 ms | 532 KB |
01-05.txt | RE | 3 ms | 532 KB |
01-06.txt | RE | 3 ms | 536 KB |
01-07.txt | RE | 3 ms | 536 KB |
01-08.txt | RE | 3 ms | 528 KB |
01-09.txt | RE | 3 ms | 536 KB |
01-10.txt | RE | 3 ms | 536 KB |
01-11.txt | RE | 3 ms | 536 KB |
01-12.txt | RE | 3 ms | 536 KB |
01-13.txt | RE | 3 ms | 536 KB |
01-14.txt | RE | 3 ms | 536 KB |
01-15.txt | RE | 3 ms | 536 KB |
01-16.txt | RE | 3 ms | 536 KB |
01-17.txt | RE | 3 ms | 532 KB |
01-18.txt | RE | 3 ms | 536 KB |
01-19.txt | RE | 3 ms | 536 KB |
01-20.txt | RE | 3 ms | 536 KB |
01-21.txt | RE | 3 ms | 536 KB |
01-22.txt | RE | 3 ms | 536 KB |
01-23.txt | RE | 3 ms | 532 KB |
01-24.txt | RE | 3 ms | 536 KB |
01-25.txt | RE | 3 ms | 536 KB |
01-26.txt | RE | 3 ms | 536 KB |
01-27.txt | RE | 3 ms | 532 KB |
01-28.txt | RE | 3 ms | 536 KB |
01-29.txt | RE | 3 ms | 532 KB |
01-30.txt | RE | 3 ms | 532 KB |
sample-01.txt | RE | 3 ms | 532 KB |
sample-02.txt | RE | 3 ms | 532 KB |
sample-03.txt | RE | 3 ms | 532 KB |