Submission #1687136
Source Code Expand
#include<bits/stdc++.h>
#define ll long long
#define N 100009
#define M 400009
using namespace std;
int n,m,tot,sz,fst[N],pnt[M],nxt[M],vis[N]; bool flag;
void add(int x,int y){
pnt[++tot]=y; nxt[tot]=fst[x]; fst[x]=tot;
}
void dfs(int x,int t){
if (!vis[x]){
sz++; vis[x]=t;
} else{
if (vis[x]!=t) flag=1;
return;
}
int i;
for (i=fst[x]; i; i=nxt[i])
dfs(pnt[i],t^3);
}
int main(){
scanf("%d%d",&n,&m);
int i,x,y;
for (i=1; i<=m; i++){
scanf("%d%d",&x,&y);
add(x,y); add(y,x);
}
ll t1=0,t2=0,t3=0;
for (i=1; i<=n; i++) if (!vis[i]){
sz=0; flag=0;
dfs(i,1);
if (sz==1) t1++; else
if (flag) t2++; else t3++;
}
printf("%lld\n",t1*(n-t1)*2+t2*t3*2+t1*t1+t2*t2+t3*t3*2);
return 0;
}
Submission Info
Submission Time
2017-10-15 20:15:59+0900
Task
A - Airport Bus
User
lych_cys
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
754 Byte
Status
RE
Exec Time
103 ms
Memory
256 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:23: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:26:22: 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
0 / 300
Status
Set Name
Test Cases
Sample
sample1.txt, sample2.txt
All
sample1.txt, sample2.txt, in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, sample1.txt, sample2.txt
Case Name
Status
Exec Time
Memory
in1.txt
WA
1 ms
256 KB
in2.txt
RE
101 ms
256 KB
in3.txt
RE
100 ms
256 KB
in4.txt
RE
101 ms
256 KB
in5.txt
WA
1 ms
256 KB
in6.txt
RE
103 ms
256 KB
in7.txt
RE
102 ms
256 KB
in8.txt
RE
102 ms
256 KB
sample1.txt
WA
1 ms
256 KB
sample2.txt
WA
1 ms
256 KB