Submission #1868522
Source Code Expand
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int N=110000;
int v[N], s, nbp;
vi adj[N];
void dfs(int x, int t) {
v[x]=t;
s++;
for(int y:adj[x]) {
if(v[y]==t) nbp=1;
if(!v[y]) dfs(y, -t);
}
}
int main() {
int i, n, m, x, y;
ll c, c1, cbp;
scanf("%d%d", &n, &m);
while(m--) {
scanf("%d%d", &x, &y);
adj[x].pb(y);
adj[y].pb(x);
}
c=c1=cbp=0;
for(i=1; i<=n; i++) if(!v[i]) {
s=nbp=0;
dfs(i, 1);
if(s==1) c1++;
else {
c++;
if(!nbp) cbp++;
}
}
printf("%lld\n", 2*c1*n-c1*c1+c*c+cbp*cbp);
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Squared Graph |
User |
Ajira |
Language |
C++14 (GCC 5.4.1) |
Score |
800 |
Code Size |
988 Byte |
Status |
AC |
Exec Time |
76 ms |
Memory |
10240 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:32:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
./Main.cpp:34:30: 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 |
2816 KB |
in10.txt |
AC |
3 ms |
3200 KB |
in11.txt |
AC |
2 ms |
2816 KB |
in12.txt |
AC |
20 ms |
6272 KB |
in13.txt |
AC |
20 ms |
6400 KB |
in14.txt |
AC |
38 ms |
6400 KB |
in15.txt |
AC |
6 ms |
3584 KB |
in16.txt |
AC |
28 ms |
4736 KB |
in17.txt |
AC |
22 ms |
5888 KB |
in18.txt |
AC |
51 ms |
7296 KB |
in19.txt |
AC |
41 ms |
7168 KB |
in2.txt |
AC |
2 ms |
2816 KB |
in20.txt |
AC |
41 ms |
7296 KB |
in21.txt |
AC |
76 ms |
10240 KB |
in22.txt |
AC |
50 ms |
6144 KB |
in23.txt |
AC |
37 ms |
5120 KB |
in24.txt |
AC |
3 ms |
3200 KB |
in25.txt |
AC |
75 ms |
10240 KB |
in26.txt |
AC |
2 ms |
2816 KB |
in27.txt |
AC |
3 ms |
2816 KB |
in28.txt |
AC |
75 ms |
10240 KB |
in3.txt |
AC |
2 ms |
2816 KB |
in4.txt |
AC |
3 ms |
2816 KB |
in5.txt |
AC |
52 ms |
5888 KB |
in6.txt |
AC |
5 ms |
3456 KB |
in7.txt |
AC |
5 ms |
3328 KB |
in8.txt |
AC |
9 ms |
4096 KB |
in9.txt |
AC |
24 ms |
5248 KB |
sample1.txt |
AC |
2 ms |
2816 KB |
sample2.txt |
AC |
2 ms |
2816 KB |