Submission #1686581
Source Code Expand
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,m,col[SZ]; Edg
bool dfs(int x)
{
bool ok=1;
for esb(x,e,b)
{
if(col[b]==-1) col[b]=!col[x],ok&=dfs(b);
else if(col[b]==col[x]) ok=0;
}
return ok;
}
int main()
{
memset(col,-1,sizeof col);
scanf("%d%d",&n,&m);
for(int i=1,a,b;i<=m;++i)
scanf("%d%d",&a,&b),adde(a,b);
ll sg=0,pa=0,pb=0;
for(int i=1;i<=n;++i)
if(col[i]==-1)
{
col[i]=0;
if(!fst[i]) ++sg;
else if(dfs(i)) ++pa;
else ++pb;
}
ll ans=sg*sg+2*sg*(n-sg)+(pa+pb)*(pa+pb)+pa*pa;
printf("%lld\n",ans);
}
Submission Info
Submission Time
2017-10-15 14:17:16+0900
Task
C - Squared Graph
User
fjzzq2002
Language
C++14 (GCC 5.4.1)
Score
800
Code Size
1587 Byte
Status
AC
Exec Time
48 ms
Memory
12928 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:47: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:49:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b),adde(a,b);
^
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
3 ms
8576 KB
in10.txt
AC
3 ms
4480 KB
in11.txt
AC
3 ms
8576 KB
in12.txt
AC
13 ms
8960 KB
in13.txt
AC
13 ms
8960 KB
in14.txt
AC
23 ms
9344 KB
in15.txt
AC
5 ms
8704 KB
in16.txt
AC
18 ms
9216 KB
in17.txt
AC
15 ms
9344 KB
in18.txt
AC
33 ms
10624 KB
in19.txt
AC
26 ms
10624 KB
in2.txt
AC
3 ms
8576 KB
in20.txt
AC
26 ms
10624 KB
in21.txt
AC
47 ms
12928 KB
in22.txt
AC
41 ms
10624 KB
in23.txt
AC
38 ms
10240 KB
in24.txt
AC
3 ms
8576 KB
in25.txt
AC
47 ms
12928 KB
in26.txt
AC
3 ms
8576 KB
in27.txt
AC
3 ms
8576 KB
in28.txt
AC
48 ms
12928 KB
in3.txt
AC
3 ms
8576 KB
in4.txt
AC
3 ms
8576 KB
in5.txt
AC
36 ms
9984 KB
in6.txt
AC
4 ms
8704 KB
in7.txt
AC
5 ms
8704 KB
in8.txt
AC
7 ms
8704 KB
in9.txt
AC
16 ms
9728 KB
sample1.txt
AC
3 ms
8576 KB
sample2.txt
AC
3 ms
8576 KB