Submission #1679689
Source Code Expand
#include <bits/stdc++.h>
#define For(i, j, k) for(int i = j; i <= k; i++)
#define pb push_back
using namespace std;
const int N = 100010;
vector<int> G[N];
int fa[N], sz[N];
int n, m;
int find(int x){
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
int col[N];
bool DFS(int o){
for(int v : G[o]){
if(!col[v]){
col[v] = 3 - col[o];
if(!DFS(v)) return false;
}
else if(col[v] == col[o]) return false;
}
return true;
}
int main(){
scanf("%d%d", &n, &m);
For(i, 1, n) fa[i] = i, sz[i] = 1;
For(i, 1, m){
int u, v;
scanf("%d%d", &u, &v);
G[u].pb(v), G[v].pb(u);
u = find(u), v = find(v);
if(u ^ v) fa[u] = v, sz[v] += sz[u];
}
int ct = n, blk = 0, blk2 = 0;
For(i, 1, n) if(fa[i] == i){
col[i] = 1;
if(sz[i] == 1) --ct;
else{
++blk;
if(DFS(i)) ++blk2;
}
}
printf("%lld\n", 1ll * n * n - 1ll * ct * ct + 1ll * blk * blk + 1ll * blk2 * blk2);
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Squared Graph |
User |
dy0607 |
Language |
C++14 (GCC 5.4.1) |
Score |
800 |
Code Size |
960 Byte |
Status |
AC |
Exec Time |
81 ms |
Memory |
8064 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:32:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
./Main.cpp:36:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &u, &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 |
3 ms |
2560 KB |
in10.txt |
AC |
4 ms |
3712 KB |
in11.txt |
AC |
3 ms |
2560 KB |
in12.txt |
AC |
23 ms |
6912 KB |
in13.txt |
AC |
23 ms |
6912 KB |
in14.txt |
AC |
42 ms |
6912 KB |
in15.txt |
AC |
7 ms |
4096 KB |
in16.txt |
AC |
31 ms |
5376 KB |
in17.txt |
AC |
24 ms |
6016 KB |
in18.txt |
AC |
56 ms |
6912 KB |
in19.txt |
AC |
43 ms |
6528 KB |
in2.txt |
AC |
3 ms |
2560 KB |
in20.txt |
AC |
43 ms |
6528 KB |
in21.txt |
AC |
81 ms |
8064 KB |
in22.txt |
AC |
49 ms |
5504 KB |
in23.txt |
AC |
36 ms |
4864 KB |
in24.txt |
AC |
4 ms |
3840 KB |
in25.txt |
AC |
81 ms |
8064 KB |
in26.txt |
AC |
3 ms |
2560 KB |
in27.txt |
AC |
3 ms |
2688 KB |
in28.txt |
AC |
80 ms |
7936 KB |
in3.txt |
AC |
3 ms |
2560 KB |
in4.txt |
AC |
2 ms |
2560 KB |
in5.txt |
AC |
55 ms |
6400 KB |
in6.txt |
AC |
6 ms |
4096 KB |
in7.txt |
AC |
5 ms |
3840 KB |
in8.txt |
AC |
10 ms |
4608 KB |
in9.txt |
AC |
25 ms |
5120 KB |
sample1.txt |
AC |
3 ms |
2560 KB |
sample2.txt |
AC |
3 ms |
2560 KB |