Submission #3230593
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int RLEN=1<<18|1; inline char nc() { static char ibuf[RLEN],*ib,*ob; (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin)); return (ib==ob) ? -1 : *ib++; } inline int rd() { char ch=nc(); int i=0,f=1; while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();} while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();} return i*f; } const int N=4e5+50; int n,q,mn[N],anc[N]; long long ans; struct data { int x,y,w; data(int x,int y,int w) : x(x),y(y),w(w) {} friend inline bool operator <(const data &a,const data &b) {return a.w<b.w;} }; vector <data> edge; inline int ga(int x) {while(x!=anc[x]) x=anc[x]=anc[anc[x]]; } int main() { n=rd(), q=rd(); for(int i=0;i<2*n;i++) mn[i]=0x3f3f3f3f; for(int i=1;i<=q;i++) { int x=rd(), y=rd(), w=rd(); mn[x]=min(mn[x],w+1); mn[y]=min(mn[y],w+2); edge.push_back(data(x,y,w)); } for(int i=1;i<2*n;i++) mn[i]=min(mn[i],mn[i-1]+2); for(int i=0;i<=n-1;i++) { int w=min(mn[i],mn[i+n]); int x=i%n, y=(i+1)%n; edge.push_back(data(x,y,w)); } sort(edge.begin(),edge.end()); for(int i=0;i<n;i++) anc[i]=i; for(auto v:edge) { int x=ga(v.x), y=ga(v.y); if(x==y) continue; ans+=v.w; anc[x]=y; } cout<<ans<<'\n'; }
Submission Info
Submission Time | |
---|---|
Task | G - Zigzag MST |
User | DZYO |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1270 Byte |
Status | WA |
Exec Time | 46 ms |
Memory | 10352 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 | WA | 1 ms | 256 KB |
01-02.txt | WA | 22 ms | 3700 KB |
01-03.txt | WA | 44 ms | 10352 KB |
01-04.txt | WA | 21 ms | 5104 KB |
01-05.txt | WA | 14 ms | 5104 KB |
01-06.txt | WA | 17 ms | 5104 KB |
01-07.txt | WA | 15 ms | 5104 KB |
01-08.txt | WA | 15 ms | 6516 KB |
01-09.txt | WA | 16 ms | 6004 KB |
01-10.txt | WA | 28 ms | 9584 KB |
01-11.txt | WA | 34 ms | 9456 KB |
01-12.txt | WA | 41 ms | 9840 KB |
01-13.txt | WA | 41 ms | 8432 KB |
01-14.txt | WA | 41 ms | 9840 KB |
01-15.txt | WA | 43 ms | 9072 KB |
01-16.txt | WA | 41 ms | 9200 KB |
01-17.txt | WA | 41 ms | 8432 KB |
01-18.txt | WA | 27 ms | 9456 KB |
01-19.txt | WA | 15 ms | 5748 KB |
01-20.txt | WA | 15 ms | 5876 KB |
01-21.txt | WA | 17 ms | 6000 KB |
01-22.txt | WA | 25 ms | 9072 KB |
01-23.txt | WA | 26 ms | 9072 KB |
01-24.txt | WA | 13 ms | 6260 KB |
01-25.txt | WA | 46 ms | 9200 KB |
01-26.txt | WA | 19 ms | 5104 KB |
01-27.txt | WA | 18 ms | 6388 KB |
01-28.txt | WA | 25 ms | 8432 KB |
01-29.txt | WA | 28 ms | 8816 KB |
01-30.txt | WA | 34 ms | 10352 KB |
sample-01.txt | WA | 1 ms | 256 KB |
sample-02.txt | WA | 1 ms | 256 KB |
sample-03.txt | WA | 1 ms | 256 KB |