Submission #1677532
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
int n,m,f[100010],dis[100010],siz[100010],a[100010],A,B,C;
void find(int x)
{
if (f[x]!=x) find(f[x]),dis[x]^=dis[f[x]],f[x]=f[f[x]];
}
void work()
{
scanf("%d %d",&n,&m);
for (int i=1; i<=n; i++) f[i]=i,siz[i]=1;
for (int i=1,u,v; i<=m; i++)
{
scanf("%d %d",&u,&v),find(u),find(v);
if (f[u]!=f[v])
siz[f[u]]+=siz[f[v]],a[f[u]]|=a[f[v]],dis[f[v]]=dis[v]^1,f[f[v]]=u;
else a[f[u]]|=dis[u]^dis[v]^1;
}
for (int i=1; i<=n; i++)
if (f[i]==i) (siz[i]==1?A:a[i]?C:B)++;
printf("%lld",1LL*A*A+2LL*A*(n-A)+2LL*B*(B+C)+1LL*C*C);
}
int main()
{
work();
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Squared Graph |
User |
YMDragon |
Language |
C++14 (GCC 5.4.1) |
Score |
800 |
Code Size |
668 Byte |
Status |
AC |
Exec Time |
55 ms |
Memory |
1792 KB |
Compile Error
./Main.cpp: In function ‘void work()’:
./Main.cpp:13: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:17:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&u,&v),find(u),find(v);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
800 / 800 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt |
All |
sample1.txt, sample2.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt |
Case Name |
Status |
Exec Time |
Memory |
in1.txt |
AC |
1 ms |
256 KB |
in10.txt |
AC |
2 ms |
1024 KB |
in11.txt |
AC |
1 ms |
256 KB |
in12.txt |
AC |
14 ms |
1792 KB |
in13.txt |
AC |
13 ms |
1792 KB |
in14.txt |
AC |
24 ms |
1792 KB |
in15.txt |
AC |
4 ms |
1792 KB |
in16.txt |
AC |
20 ms |
1792 KB |
in17.txt |
AC |
15 ms |
1792 KB |
in18.txt |
AC |
36 ms |
1792 KB |
in19.txt |
AC |
28 ms |
1792 KB |
in2.txt |
AC |
1 ms |
256 KB |
in20.txt |
AC |
28 ms |
1792 KB |
in21.txt |
AC |
55 ms |
1792 KB |
in22.txt |
AC |
37 ms |
384 KB |
in23.txt |
AC |
34 ms |
256 KB |
in24.txt |
AC |
3 ms |
1792 KB |
in25.txt |
AC |
54 ms |
1792 KB |
in26.txt |
AC |
1 ms |
256 KB |
in27.txt |
AC |
2 ms |
256 KB |
in28.txt |
AC |
55 ms |
1792 KB |
in3.txt |
AC |
1 ms |
256 KB |
in4.txt |
AC |
1 ms |
256 KB |
in5.txt |
AC |
38 ms |
1792 KB |
in6.txt |
AC |
4 ms |
1792 KB |
in7.txt |
AC |
4 ms |
1792 KB |
in8.txt |
AC |
6 ms |
1792 KB |
in9.txt |
AC |
17 ms |
1792 KB |
sample1.txt |
AC |
1 ms |
256 KB |
sample2.txt |
AC |
1 ms |
256 KB |