Submission #1587920
Source Code Expand
#include<cstdio> int N,M; struct edge{int to;edge*next;}E[400010],*ne=E,*first[100010]; void link(int u,int v){*ne=(edge){v,first[u]};first[u]=ne++;} bool vis[100010],col[100010]; int tot; bool dfs(int i){ vis[i]=1;++tot; bool r=1; for(edge*e=first[i];e;e=e->next){ if(!vis[e->to])col[e->to]=!col[i],r|=dfs(e->to); else if(col[e->to]==col[i])r=0; } return r; } int main(){ scanf("%d%d",&N,&M); for(int i=0,u,v;i<M;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u); int a=0,b=0,s=0; for(int i=1;i<=N;i++)if(!vis[i]){ int o=tot; if(dfs(i))(o=tot-o)>1?++a:++s; else++b; } long long ans=(2ll*N-s)*s+(a+b)*1ll*(a+b)+1ll*a*a; printf("%lld\n",ans); }
Submission Info
Submission Time | |
---|---|
Task | C - Squared Graph |
User | vjudge2 |
Language | Bash (GNU bash v4.3.11) |
Score | 0 |
Code Size | 659 Byte |
Status | RE |
Exec Time | 4 ms |
Memory | 616 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | RE | 3 ms | 544 KB |
in10.txt | RE | 4 ms | 548 KB |
in11.txt | RE | 3 ms | 552 KB |
in12.txt | RE | 3 ms | 556 KB |
in13.txt | RE | 4 ms | 556 KB |
in14.txt | RE | 4 ms | 548 KB |
in15.txt | RE | 4 ms | 548 KB |
in16.txt | RE | 3 ms | 548 KB |
in17.txt | RE | 3 ms | 552 KB |
in18.txt | RE | 3 ms | 548 KB |
in19.txt | RE | 4 ms | 552 KB |
in2.txt | RE | 4 ms | 616 KB |
in20.txt | RE | 3 ms | 552 KB |
in21.txt | RE | 3 ms | 548 KB |
in22.txt | RE | 4 ms | 548 KB |
in23.txt | RE | 4 ms | 548 KB |
in24.txt | RE | 4 ms | 552 KB |
in25.txt | RE | 3 ms | 548 KB |
in26.txt | RE | 4 ms | 548 KB |
in27.txt | RE | 3 ms | 548 KB |
in28.txt | RE | 4 ms | 548 KB |
in3.txt | RE | 4 ms | 552 KB |
in4.txt | RE | 4 ms | 552 KB |
in5.txt | RE | 4 ms | 552 KB |
in6.txt | RE | 4 ms | 552 KB |
in7.txt | RE | 4 ms | 552 KB |
in8.txt | RE | 3 ms | 552 KB |
in9.txt | RE | 4 ms | 548 KB |
sample1.txt | RE | 4 ms | 552 KB |
sample2.txt | RE | 4 ms | 548 KB |