Submission #1588984
Source Code Expand
#include<bits/stdc++.h> #define MAXN 1000000+10 using namespace std; int n,m,I,P,Q; int tot,head[MAXN],to[MAXN],nxt[MAXN],linker[MAXN]; bool f,vis[MAXN]; void add(int x,int y){ cnt++; to[cnt]=y; nxt[cnt]=head[x]; head[x]=cnt; } void dfs(int x,int fa){ vis[x]=true; linker[x]=linker[fa]^1; for(int i=head[x];i;i=nxt[i]){ int y=to[i]; if(y!=fa){ if(vis[y]) if(linker[x]==linker[y])f=true; else dfs(y,x); } } } int main(){ scanf("%d%d",&n,&m); int x,y; for(int i=0;i<m;i++){ cin>>x>>y; add(x,y); add(y,x); } for(int i=1;i<=n;i++) if(!vis[i]){ if(!head[i]){ I++; vis[i]=true; continue; } f=false; dfs(i,0); if(f)P++; else Q++; } long long ans=2LL*I*n-1LL*I*I+1LL*P*P+2LL*P*Q+2LL*Q*Q; printf("%lld\n",ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Squared Graph |
User | vjudge5 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 789 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘void add(int, int)’: ./Main.cpp:8:2: error: ‘cnt’ was not declared in this scope cnt++; ^ ./Main.cpp: In function ‘int main()’: ./Main.cpp:26:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&n,&m); ^