Submission #6089802
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
namespace Flandle_Scarlet
{
#define N 200100
#define int long long
struct Edge
{
int u,v,w;
const bool operator<(Edge CompWith) const
{
return w<CompWith.w;
}
}E[N<<1];int cnt=0;
class DSU
{
public:
int Father[N],Cnt[N];
void Init()
{
for(int i=0;i<N;i++)
{
Father[i]=i;
Cnt[i]=1;
}
}
int Find(int x)
{
return (x==Father[x])?x:(Father[x]=Find(Father[x]));
}
void Merge(int x,int y)
{
int ax=Find(x),ay=Find(y);
if (Cnt[ax]<Cnt[ay])
{
Cnt[ay]+=Cnt[ax];
Father[ax]=ay;
}
else
{
Cnt[ax]+=Cnt[ay];
Father[ay]=ax;
}
}
}D;
int n,q;
int d[N];
void Input()
{
scanf("%lld%lld",&n,&q);
memset(d,0x3f,sizeof(d));
for(int i=1;i<=q;++i)
{
int u,v,w;
scanf("%lld%lld%lld",&u,&v,&w);
E[++cnt]=(Edge){u,v,w};
d[u]=min(d[u],w+1);
d[v]=min(d[v],w+2);
}
}
void Soviet()
{
for(int i=0;i<n;++i)
{
d[i]=min(d[i],d[(i+n-1)%n]+2);
}
for(int i=0;i<n;++i)
{
d[i]=min(d[i],d[(i+n-1)%n]+2);
}
for(int i=0;i<=n;++i)
{
E[++cnt]=(Edge){i,(i+1)%n,d[i]};
}
sort(E+1,E+cnt+1);
D.Init();
int ans=0;int rest=n;
for(int i=1;i<=cnt and rest>1;++i)
{
int u=E[i].u,v=E[i].v,w=E[i].w;
if (D.Find(u)!=D.Find(v))
{
D.Merge(u,v);
ans+=w;
--rest;
}
}
printf("%lld\n",ans);
}
void IsMyWife()
{
if (0)
{
freopen("","r",stdin);
freopen("","w",stdout);
}
Input();
Soviet();
}
#undef int //long long
};
int main()
{
Flandle_Scarlet::IsMyWife();
return 0;
}
Submission Info
Submission Time |
|
Task |
G - Zigzag MST |
User |
luogu_bot3 |
Language |
C++14 (GCC 5.4.1) |
Score |
1300 |
Code Size |
2442 Byte |
Status |
AC |
Exec Time |
99 ms |
Memory |
14336 KB |
Compile Error
./Main.cpp: In function ‘void Flandle_Scarlet::Input()’:
./Main.cpp:50:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&n,&q);
^
./Main.cpp:55:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld",&u,&v,&w);
^
./Main.cpp: In function ‘void Flandle_Scarlet::IsMyWife()’:
./Main.cpp:96:34: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen("","r",stdin);
^
./Main.cpp:97:35: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen("","w",stdout);
...
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 |
3 ms |
6400 KB |
01-02.txt |
AC |
60 ms |
10496 KB |
01-03.txt |
AC |
93 ms |
14336 KB |
01-04.txt |
AC |
26 ms |
10496 KB |
01-05.txt |
AC |
19 ms |
10496 KB |
01-06.txt |
AC |
22 ms |
10496 KB |
01-07.txt |
AC |
21 ms |
10496 KB |
01-08.txt |
AC |
20 ms |
10496 KB |
01-09.txt |
AC |
23 ms |
10496 KB |
01-10.txt |
AC |
60 ms |
12544 KB |
01-11.txt |
AC |
78 ms |
12544 KB |
01-12.txt |
AC |
95 ms |
14208 KB |
01-13.txt |
AC |
98 ms |
14336 KB |
01-14.txt |
AC |
98 ms |
14336 KB |
01-15.txt |
AC |
93 ms |
14336 KB |
01-16.txt |
AC |
97 ms |
14336 KB |
01-17.txt |
AC |
88 ms |
14336 KB |
01-18.txt |
AC |
79 ms |
14336 KB |
01-19.txt |
AC |
21 ms |
10496 KB |
01-20.txt |
AC |
20 ms |
10496 KB |
01-21.txt |
AC |
36 ms |
12544 KB |
01-22.txt |
AC |
85 ms |
14336 KB |
01-23.txt |
AC |
85 ms |
14336 KB |
01-24.txt |
AC |
21 ms |
10496 KB |
01-25.txt |
AC |
99 ms |
14336 KB |
01-26.txt |
AC |
26 ms |
10496 KB |
01-27.txt |
AC |
26 ms |
10496 KB |
01-28.txt |
AC |
58 ms |
12544 KB |
01-29.txt |
AC |
75 ms |
12544 KB |
01-30.txt |
AC |
86 ms |
14336 KB |
sample-01.txt |
AC |
3 ms |
6400 KB |
sample-02.txt |
AC |
3 ms |
6400 KB |
sample-03.txt |
AC |
3 ms |
6400 KB |