Submission #1673721
Source Code Expand
#include<bits/stdc++.h>
#define N 400005
using namespace std;
int n,m,x,y,to[N],fst[N],nxt[N],a,b,c,flag,vis[N],col[N],l;
void link(int x,int y)
{
to[++l]=y;nxt[l]=fst[x];fst[x]=l;
to[++l]=x;nxt[l]=fst[y];fst[y]=l;
}
void dfs(int x,int y)
{
if (vis[x])
{
if (col[x]!=y) flag=1;
return;
}
vis[x]=1;col[x]=y;
for (int i=fst[x];i;i=nxt[i])
dfs(to[i],y^1);
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
link(x,y);
}
for (int i=1;i<=n;i++)
{
if (!vis[i])
{
if (fst[i])
{
flag=0;
dfs(i,0);
if (flag) b++;else c++;
}
else a++;
}
}
printf("%lld\n",2LL*a*n-1LL*a*a+1LL*b*b+2LL*c*c+2LL*b*c);
}
Submission Info
Submission Time
2017-10-10 12:25:20+0900
Task
C - Squared Graph
User
miaom
Language
C++14 (GCC 5.4.1)
Score
800
Code Size
716 Byte
Status
AC
Exec Time
54 ms
Memory
8576 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:23:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
./Main.cpp:26:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
^
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
2 ms
4352 KB
in10.txt
AC
2 ms
2304 KB
in11.txt
AC
2 ms
4352 KB
in12.txt
AC
13 ms
5504 KB
in13.txt
AC
13 ms
5504 KB
in14.txt
AC
24 ms
5888 KB
in15.txt
AC
5 ms
5248 KB
in16.txt
AC
19 ms
5760 KB
in17.txt
AC
15 ms
5760 KB
in18.txt
AC
36 ms
6912 KB
in19.txt
AC
28 ms
6784 KB
in2.txt
AC
2 ms
4352 KB
in20.txt
AC
28 ms
6784 KB
in21.txt
AC
54 ms
8576 KB
in22.txt
AC
44 ms
6272 KB
in23.txt
AC
40 ms
5888 KB
in24.txt
AC
3 ms
5120 KB
in25.txt
AC
53 ms
8576 KB
in26.txt
AC
2 ms
4352 KB
in27.txt
AC
2 ms
4352 KB
in28.txt
AC
54 ms
8576 KB
in3.txt
AC
2 ms
4352 KB
in4.txt
AC
2 ms
4352 KB
in5.txt
AC
41 ms
6400 KB
in6.txt
AC
4 ms
5120 KB
in7.txt
AC
4 ms
5248 KB
in8.txt
AC
9 ms
5248 KB
in9.txt
AC
17 ms
6016 KB
sample1.txt
AC
2 ms
4352 KB
sample2.txt
AC
2 ms
4352 KB