Submission #1573300
Source Code Expand
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #define ll long long using namespace std; const int N=100005; int n,m,x,y; ll ans; int sz[N],f[N]; int find(int k){ if (f[k]!=k) f[k]=find(f[k]); return f[k]; } int main(){ scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) f[i]=i,sz[i]=1; for (int i=1;i<=m;i++){ scanf("%d%d",&x,&y); x=find(x); y=find(y); if (x!=y){ f[y]=x; sz[x]+=sz[y]; } } ans=1ll*n*n; for (int i=1;i<=n;i++) if (find(i)==i){ if (sz[i]==2) ans-=2; if (sz[i]==1) continue; if (sz[i]>2) ans-=1ll*sz[i]*sz[i]-1ll; } printf("%lld\n",ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Squared Graph |
User | vjudge5 |
Language | Bash (GNU bash v4.3.11) |
Score | 0 |
Code Size | 659 Byte |
Status | RE |
Exec Time | 4 ms |
Memory | 592 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 | 4 ms | 592 KB |
in10.txt | RE | 4 ms | 584 KB |
in11.txt | RE | 4 ms | 592 KB |
in12.txt | RE | 4 ms | 580 KB |
in13.txt | RE | 4 ms | 580 KB |
in14.txt | RE | 4 ms | 584 KB |
in15.txt | RE | 4 ms | 584 KB |
in16.txt | RE | 4 ms | 584 KB |
in17.txt | RE | 4 ms | 592 KB |
in18.txt | RE | 4 ms | 584 KB |
in19.txt | RE | 4 ms | 584 KB |
in2.txt | RE | 4 ms | 584 KB |
in20.txt | RE | 4 ms | 584 KB |
in21.txt | RE | 4 ms | 584 KB |
in22.txt | RE | 4 ms | 584 KB |
in23.txt | RE | 4 ms | 584 KB |
in24.txt | RE | 4 ms | 592 KB |
in25.txt | RE | 4 ms | 592 KB |
in26.txt | RE | 4 ms | 592 KB |
in27.txt | RE | 4 ms | 592 KB |
in28.txt | RE | 4 ms | 584 KB |
in3.txt | RE | 4 ms | 580 KB |
in4.txt | RE | 4 ms | 584 KB |
in5.txt | RE | 4 ms | 584 KB |
in6.txt | RE | 4 ms | 592 KB |
in7.txt | RE | 4 ms | 580 KB |
in8.txt | RE | 4 ms | 584 KB |
in9.txt | RE | 4 ms | 580 KB |
sample1.txt | RE | 4 ms | 580 KB |
sample2.txt | RE | 4 ms | 592 KB |