Submission #1371381


Source Code Expand

#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what
 
using namespace std;
 
const int N = (int) 1e5 + 10;
const int M = (int) 101;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int INF1 = (int) 1e9 + 3;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;
 
int n, m;
vector<int> v[N];
int u[N], clr[N];
int bad;
 
void dfs(int x, int c = 0) {
  u[x] = 1;
  clr[x] = c;
  for (auto it : v[x]) {
    if (!u[it]) 
        dfs(it, clr[x] ^ 1);
    else if (clr[x] == clr[it]) {
        bad = 1;
    }
  }
}
 
int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n >> m;
    while (m--) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      v[x].pb(y);
      v[y].pb(x);
    }
    ll isolated = 0, bipartite = 0, comp = 0;
    for (int i = 0; i < n; i++) {
      if (!u[i]) {
        if (v[i].empty()) {
            ++isolated;
        } else {
            bad = 0;
            dfs(i);
            bipartite += 1 - bad;
            comp++;
        }
      }
    }
    cerr << isolated << " " << bipartite << " " << (comp - bipartite) << endl;
    ll ans = bipartite * bipartite * 2;
    ans += isolated * (n - isolated) * 2;
    ans += isolated * isolated;
    ans += (comp - bipartite) * bipartite * 2;
    ans += (comp - bipartite) * (comp - bipartite);
    cout << ans;
    return 0;
}

Submission Info

Submission Time
Task C - Squared Graph
User Nurlykhan
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1890 Byte
Status AC
Exec Time 188 ms
Memory 9472 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 2
AC × 32
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 2 ms 2560 KB
in11.txt AC 2 ms 2560 KB
in12.txt AC 47 ms 6528 KB
in13.txt AC 47 ms 6528 KB
in14.txt AC 91 ms 6528 KB
in15.txt AC 10 ms 3712 KB
in16.txt AC 69 ms 4992 KB
in17.txt AC 51 ms 5888 KB
in18.txt AC 125 ms 7168 KB
in19.txt AC 93 ms 6912 KB
in2.txt AC 2 ms 2560 KB
in20.txt AC 94 ms 7040 KB
in21.txt AC 179 ms 9344 KB
in22.txt AC 137 ms 5760 KB
in23.txt AC 110 ms 4864 KB
in24.txt AC 3 ms 3456 KB
in25.txt AC 188 ms 9344 KB
in26.txt AC 2 ms 2560 KB
in27.txt AC 3 ms 2688 KB
in28.txt AC 181 ms 9472 KB
in3.txt AC 2 ms 2560 KB
in4.txt AC 2 ms 2560 KB
in5.txt AC 138 ms 6016 KB
in6.txt AC 8 ms 3712 KB
in7.txt AC 8 ms 3456 KB
in8.txt AC 17 ms 4224 KB
in9.txt AC 54 ms 5120 KB
sample1.txt AC 2 ms 2560 KB
sample2.txt AC 2 ms 2560 KB