Submission #1816061
Source Code Expand
#include <iostream> #include <iomanip> // << fixed << setprecision(xxx) #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <vector> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <complex> #include <tuple> // get<n>(xxx) #include <queue> #include <stack> #include <map> // if (M.find(key) != M.end()) { } #include <set> // S.insert(M); // if (S.find(key) != S.end()) { } // for (auto it=S.begin(); it != S.end(); it++) { } // auto it = S.lower_bound(M); #include <random> // random_device rd; mt19937 mt(rd()); #include <cctype> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> // atoi(xxx) using namespace std; #define DEBUG 0 // change 0 -> 1 if we need debug. // insert #if<tab> by my emacs. #if DEBUG == 1 ... #end typedef long long ll; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; // const int C = 1e6+10; // const ll M = 1000000007; ll hen(ll n) { return n * (n-1) / 2; } int main () { int N; cin >> N; int M; cin >> M; vector<int> V[100010]; for (auto i = 0; i < M; ++i) { int a, b; cin >> a >> b; a--; b--; V[a].push_back(b); V[b].push_back(a); } bool visited[100010]; fill(visited, visited+100010, false); stack<int> S; S.push(0); int zero = 0; while (!S.empty()) { int src = S.top(); S.pop(); if (!visited[src]) { visited[src] = true; zero++; for (auto x : V[src]) { if (!visited[x]) { S.push(x); } } } } S.push(1); int one = 0; while (!S.empty()) { int src = S.top(); S.pop(); if (!visited[src]) { visited[src] = true; one++; for (auto x : V[src]) { if (!visited[x]) { S.push(x); } } } } if (one < zero) swap(one, zero); one = N - zero; cout << hen(one) + hen(zero) - M << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Shock |
User | kazunetakahashi |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 1996 Byte |
Status | AC |
Exec Time | 82 ms |
Memory | 5888 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | a01, a02, a03 |
All | a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
a01 | AC | 2 ms | 2688 KB |
a02 | AC | 2 ms | 2688 KB |
a03 | AC | 2 ms | 2688 KB |
b04 | AC | 2 ms | 2688 KB |
b05 | AC | 2 ms | 2688 KB |
b06 | AC | 68 ms | 5760 KB |
b07 | AC | 70 ms | 5760 KB |
b08 | AC | 36 ms | 5760 KB |
b09 | AC | 68 ms | 5760 KB |
b10 | AC | 67 ms | 5760 KB |
b11 | AC | 2 ms | 2688 KB |
b12 | AC | 73 ms | 5504 KB |
b13 | AC | 77 ms | 5888 KB |
b14 | AC | 77 ms | 5888 KB |
b15 | AC | 82 ms | 5888 KB |
b16 | AC | 75 ms | 5632 KB |
b17 | AC | 75 ms | 5504 KB |
b18 | AC | 60 ms | 4096 KB |
b19 | AC | 60 ms | 4096 KB |
b20 | AC | 5 ms | 2816 KB |
b21 | AC | 13 ms | 3072 KB |
b22 | AC | 73 ms | 5504 KB |
b23 | AC | 77 ms | 5248 KB |