Submission #1178680
Source Code Expand
#include<bits/stdc++.h>
#define N 400005
#define LL long long
using namespace std;
int n,m,a[N],f[N]; LL ans;
struct edge{
int x,y,z;
edge(int _x=0,int _y=0,int _z=0){ x=_x,y=_y,z=_z;}
}G[N];
int find(int x){ return f[x] ? f[x]=find(f[x]) : x;}
bool cmp(edge p,edge q){ return p.z<q.z;}
int main()
{
int i,fx,fy;
scanf("%d %d",&n,&m);
memset(a,127,sizeof(a));
for(i=1;i<=m;i++){
scanf("%d %d %d",&G[i].x,&G[i].y,&G[i].z);
G[i].x++,G[i].y++;
a[G[i].x]=min(a[G[i].x],G[i].z+1);
a[G[i].y]=min(a[G[i].y],G[i].z+2);
}
for(i=2;i<=2*n;i++)
a[i]=min(a[i],a[i-1]+2);
for(i=1;i<=n;i++)
G[++m]=edge(i,i%n+1,min(a[i],a[i+n]));
sort(G+1,G+m+1,cmp);
for(i=1;i<=m;i++){
fx=find(G[i].x);
fy=find(G[i].y);
if(fx!=fy)
f[fx]=fy,ans+=G[i].z;
}
cout<<ans;
return 0;
}
Submission Info
Submission Time |
|
Task |
G - Zigzag MST |
User |
MemorySlices |
Language |
C++14 (GCC 5.4.1) |
Score |
1300 |
Code Size |
822 Byte |
Status |
AC |
Exec Time |
119 ms |
Memory |
11008 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&m);
^
./Main.cpp:18:44: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&G[i].x,&G[i].y,&G[i].z);
^
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, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
4 ms |
7936 KB |
01-02.txt |
AC |
70 ms |
7936 KB |
01-03.txt |
AC |
103 ms |
8192 KB |
01-04.txt |
AC |
33 ms |
10240 KB |
01-05.txt |
AC |
22 ms |
8960 KB |
01-06.txt |
AC |
28 ms |
9472 KB |
01-07.txt |
AC |
23 ms |
8320 KB |
01-08.txt |
AC |
23 ms |
8064 KB |
01-09.txt |
AC |
28 ms |
7936 KB |
01-10.txt |
AC |
62 ms |
7936 KB |
01-11.txt |
AC |
89 ms |
7936 KB |
01-12.txt |
AC |
102 ms |
7936 KB |
01-13.txt |
AC |
103 ms |
7936 KB |
01-14.txt |
AC |
103 ms |
7936 KB |
01-15.txt |
AC |
105 ms |
7936 KB |
01-16.txt |
AC |
102 ms |
7936 KB |
01-17.txt |
AC |
103 ms |
7936 KB |
01-18.txt |
AC |
84 ms |
11008 KB |
01-19.txt |
AC |
23 ms |
8320 KB |
01-20.txt |
AC |
24 ms |
7936 KB |
01-21.txt |
AC |
44 ms |
7936 KB |
01-22.txt |
AC |
87 ms |
7936 KB |
01-23.txt |
AC |
87 ms |
7936 KB |
01-24.txt |
AC |
24 ms |
11008 KB |
01-25.txt |
AC |
119 ms |
11008 KB |
01-26.txt |
AC |
34 ms |
10624 KB |
01-27.txt |
AC |
31 ms |
9472 KB |
01-28.txt |
AC |
68 ms |
9472 KB |
01-29.txt |
AC |
86 ms |
8832 KB |
01-30.txt |
AC |
100 ms |
9472 KB |
sample-01.txt |
AC |
4 ms |
7936 KB |
sample-02.txt |
AC |
4 ms |
7936 KB |
sample-03.txt |
AC |
4 ms |
7936 KB |