Submission #1627485
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) int n,m; vector<int>edge[100005]; int col[100005]; bool bad[100005]; bool used[100005]; vector<int>C; int cnt; void dfs(int v,int p,int c){ if(used[v]) return; used[v] = 1; if(col[v] && col[v]!=c) bad[p]=1; col[v] = c; cnt++; for(int i=0;i<edge[v].size();i++){ if(used[edge[v][i]] == 0){ dfs(edge[v][i],p,-1*c); } else if(col[edge[v][i]] && col[edge[v][i]]==c)bad[p]=1; } } int main(){ cin>>n>>m; for(int i=0;i<m;i++){ int a,b;cin>>a>>b; edge[a].pb(b); edge[b].pb(a); } ll ans = 0; int cnt2; for(int i=1;i<=n;i++){ if(used[i]) continue; cnt=0; dfs(i,i,1); if(cnt==1); else if(bad[i]) ans++; else ans+=2; if(cnt!=1) C.pb((bad[i]?1:2)); else cnt2++; } ans+=1LL*n*n-1LL*(n-cnt2)*(n-cnt2); //cout<<ans<<endl; for(int i=0;i<C.size();i++){ for(int j=i+1;j<C.size();j++){ if(C[i]==2&&C[j]==2) ans+=4; else ans+=2; } } cout<<ans<<endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Squared Graph |
User | IH19980412 |
Language | C++14 (GCC 5.4.1) |
Score | 800 |
Code Size | 1547 Byte |
Status | AC |
Exec Time | 1272 ms |
Memory | 11904 KB |
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 | 2560 KB |
in10.txt | AC | 3 ms | 3072 KB |
in11.txt | AC | 2 ms | 2560 KB |
in12.txt | AC | 1257 ms | 6528 KB |
in13.txt | AC | 1272 ms | 6528 KB |
in14.txt | AC | 455 ms | 6656 KB |
in15.txt | AC | 14 ms | 3456 KB |
in16.txt | AC | 90 ms | 4864 KB |
in17.txt | AC | 461 ms | 6272 KB |
in18.txt | AC | 269 ms | 8064 KB |
in19.txt | AC | 101 ms | 7936 KB |
in2.txt | AC | 2 ms | 2560 KB |
in20.txt | AC | 107 ms | 7936 KB |
in21.txt | AC | 197 ms | 11904 KB |
in22.txt | AC | 139 ms | 6272 KB |
in23.txt | AC | 110 ms | 4864 KB |
in24.txt | AC | 4 ms | 3072 KB |
in25.txt | AC | 190 ms | 11904 KB |
in26.txt | AC | 2 ms | 2560 KB |
in27.txt | AC | 3 ms | 2688 KB |
in28.txt | AC | 195 ms | 11904 KB |
in3.txt | AC | 2 ms | 2560 KB |
in4.txt | AC | 2 ms | 2560 KB |
in5.txt | AC | 159 ms | 5888 KB |
in6.txt | AC | 17 ms | 3456 KB |
in7.txt | AC | 9 ms | 3328 KB |
in8.txt | AC | 86 ms | 4096 KB |
in9.txt | AC | 85 ms | 5504 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |