Submission #994551
Source Code Expand
#include<iostream> #include<cstdio> #include<algorithm> #include<set> #include<map> #include<queue> #include<cassert> #define PB push_back #define MP make_pair #define sz(v) (in((v).size())) #define forn(i,n) for(in i=0;i<(n);++i) #define forv(i,v) forn(i,sz(v)) #define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i) #define all(v) (v).begin(),(v).end() using namespace std; typedef long long in; typedef vector<in> VI; typedef vector<VI> VVI; struct unifnd{ VI ht,pr; in fnd(in a){ in ta=a; while(a!=pr[a])a=pr[a]; in tt=ta; while(ta!=a){ tt=pr[ta]; pr[ta]=a; ta=tt; } return a; } void uni(in a, in b){ a=fnd(a); b=fnd(b); if(a==b)return; if(ht[b]<ht[a])swap(a,b); pr[a]=b; ht[b]+=(ht[a]==ht[b]); } void ini(in n){ ht.resize(n); pr.resize(n); forn(i,n){ ht[i]=0; pr[i]=i; } } }; unifnd tfd; VI a,b,c; struct cand{ in id; cand(in z=0){ id=z; } bool operator<(const cand cp)const{ return c[id]>c[cp.id]; } }; priority_queue<cand> q; int main(){ ios::sync_with_stdio(0); cin.tie(0); in n,qq; cin>>n>>qq; tfd.ini(n); in sm=0; in ta,tb,tc; forn(z,qq){ cin>>ta>>tb>>tc; a.PB(ta%n); b.PB(tb%n); c.PB(tc); a.PB((ta+1)%n); b.PB(tb%n); c.PB(tc+1); q.push(cand(2*z)); q.push(cand(2*z+1)); } in u; while(!q.empty()){ u=q.top().id; q.pop(); if(tfd.fnd(a[u])==tfd.fnd(b[u])) continue; tfd.uni(a[u],b[u]); sm+=c[u]; a[u]=(a[u]+1)%n; b[u]=(b[u]+1)%n; c[u]+=2; q.push(cand(u)); } cout<<sm<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | G - Zigzag MST |
User | w4yneb0t |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 1724 Byte |
Status | AC |
Exec Time | 369 ms |
Memory | 16052 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 | 249 ms | 12852 KB |
01-03.txt | AC | 313 ms | 16052 KB |
01-04.txt | AC | 14 ms | 3328 KB |
01-05.txt | AC | 15 ms | 3328 KB |
01-06.txt | AC | 18 ms | 3328 KB |
01-07.txt | AC | 22 ms | 3456 KB |
01-08.txt | AC | 30 ms | 3456 KB |
01-09.txt | AC | 49 ms | 4352 KB |
01-10.txt | AC | 182 ms | 9796 KB |
01-11.txt | AC | 308 ms | 14516 KB |
01-12.txt | AC | 355 ms | 16052 KB |
01-13.txt | AC | 369 ms | 16052 KB |
01-14.txt | AC | 346 ms | 16052 KB |
01-15.txt | AC | 340 ms | 16052 KB |
01-16.txt | AC | 349 ms | 16052 KB |
01-17.txt | AC | 360 ms | 16052 KB |
01-18.txt | AC | 168 ms | 16052 KB |
01-19.txt | AC | 15 ms | 3328 KB |
01-20.txt | AC | 34 ms | 3584 KB |
01-21.txt | AC | 87 ms | 7124 KB |
01-22.txt | AC | 221 ms | 16052 KB |
01-23.txt | AC | 216 ms | 16052 KB |
01-24.txt | AC | 25 ms | 4352 KB |
01-25.txt | AC | 202 ms | 16052 KB |
01-26.txt | AC | 14 ms | 3328 KB |
01-27.txt | AC | 35 ms | 4352 KB |
01-28.txt | AC | 133 ms | 11204 KB |
01-29.txt | AC | 187 ms | 14644 KB |
01-30.txt | AC | 203 ms | 16052 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 |