Submission #1370856


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair <int, int> pii;
typedef long double ld;
typedef vector <ll> vi;

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int n, m;
vi g[N];
int shit, cnt;
int u[N], c[N];

void dfs(int x) {
    u[x] = 1;
    ++cnt;
    for (auto to : g[x]) {
        if (u[to] && c[to] == c[x]) shit = 1;
        if (!u[to]) {
            c[to] = c[x] ^ 1;
            dfs(to);
        }
    }
}

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    forn(i, 1, m) {
        int f, t;
        cin >> f >> t;
        g[f].pb(t);
        g[t].pb(f);
    }

    ll a = 0, b = 0, c = 0;
    forn(i, 1, n) {
        if (u[i]) continue;
        if (g[i].size() == 0) {
            ++c;
            continue;
        }
        shit = 0;
        dfs(i);
        if (!shit) ++a;
        else ++b;
    }
    cout << 2 * a * a + 2 * a * b + b * b + (2 * c * n - c * c) << "\n";

    return 0;
}

Submission Info

Submission Time
Task C - Squared Graph
User sancho
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1313 Byte
Status AC
Exec Time 103 ms
Memory 61056 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 18 ms 50432 KB
in10.txt AC 18 ms 48384 KB
in11.txt AC 18 ms 50432 KB
in12.txt AC 41 ms 56064 KB
in13.txt AC 40 ms 56064 KB
in14.txt AC 57 ms 56064 KB
in15.txt AC 23 ms 53248 KB
in16.txt AC 47 ms 55424 KB
in17.txt AC 42 ms 55680 KB
in18.txt AC 71 ms 57728 KB
in19.txt AC 60 ms 57216 KB
in2.txt AC 18 ms 50432 KB
in20.txt AC 60 ms 57344 KB
in21.txt AC 101 ms 61056 KB
in22.txt AC 67 ms 56192 KB
in23.txt AC 54 ms 54912 KB
in24.txt AC 19 ms 52864 KB
in25.txt AC 103 ms 60928 KB
in26.txt AC 18 ms 50432 KB
in27.txt AC 18 ms 50560 KB
in28.txt AC 97 ms 61056 KB
in3.txt AC 18 ms 50432 KB
in4.txt AC 18 ms 50560 KB
in5.txt AC 69 ms 57472 KB
in6.txt AC 22 ms 53248 KB
in7.txt AC 21 ms 53248 KB
in8.txt AC 26 ms 53760 KB
in9.txt AC 41 ms 55296 KB
sample1.txt AC 18 ms 50432 KB
sample2.txt AC 18 ms 50432 KB