Submission #1371396
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 += 2 * isolated * (isolated - 1) + 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 | 0 |
Code Size | 1911 Byte |
Status | WA |
Exec Time | 185 ms |
Memory | 9472 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 | WA | 2 ms | 2560 KB |
in10.txt | WA | 3 ms | 2560 KB |
in11.txt | WA | 2 ms | 2560 KB |
in12.txt | WA | 46 ms | 6400 KB |
in13.txt | AC | 47 ms | 6528 KB |
in14.txt | AC | 90 ms | 6528 KB |
in15.txt | WA | 10 ms | 3712 KB |
in16.txt | WA | 68 ms | 4992 KB |
in17.txt | WA | 51 ms | 5888 KB |
in18.txt | WA | 123 ms | 7168 KB |
in19.txt | WA | 93 ms | 6912 KB |
in2.txt | WA | 2 ms | 2560 KB |
in20.txt | WA | 95 ms | 7040 KB |
in21.txt | WA | 181 ms | 9344 KB |
in22.txt | AC | 138 ms | 5760 KB |
in23.txt | AC | 109 ms | 4864 KB |
in24.txt | WA | 3 ms | 3456 KB |
in25.txt | WA | 185 ms | 9344 KB |
in26.txt | WA | 2 ms | 2560 KB |
in27.txt | WA | 3 ms | 2688 KB |
in28.txt | WA | 179 ms | 9472 KB |
in3.txt | WA | 2 ms | 2560 KB |
in4.txt | AC | 3 ms | 2560 KB |
in5.txt | WA | 139 ms | 6016 KB |
in6.txt | WA | 8 ms | 3712 KB |
in7.txt | WA | 8 ms | 3456 KB |
in8.txt | WA | 17 ms | 4224 KB |
in9.txt | WA | 54 ms | 5120 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |