Submission #1870684
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS #include <vector> #include <iostream> #include <string.h> #include <set> #include <algorithm> #include <cmath> #include <queue> using namespace std; typedef double LD; typedef long long LL; typedef pair<int, int> PII; #define MP make_pair #define PB push_back #define FOR(i,a,b) for(int i = (a); i < (b); ++i) #define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i) #define REP(i, t) FOR(i,0,t) #define ALL(a) a.begin(), a.end() #define SZ(a) (int)((a).size()) const LL MOD = 1000000007; const int INF = 1e9; const LL LINF = 1LL * INF * INF; const int MAXN = 100007; const LD EPS = 1e-7; vector <int> G[MAXN]; bool bip, used[MAXN]; int col[MAXN]; void dfs(int v) { used[v] = true; REP(i, SZ(G[v])) { int to = G[v][i]; if (!used[to]) { col[to] = 3 - col[v]; dfs(to); } if (col[to] != 3 - col[v]) bip = false; } } int main() { ios_base::sync_with_stdio(0); //freopen("In.txt", "r", stdin); int n, m; cin >> n >> m; REP(i, m) { int u, v; cin >> u >> v; --u; --v; G[u].push_back(v); G[v].push_back(u); } LL b = 0, c = 0, c1 = 0; REP(i, n) { if (SZ(G[i]) == 0) { ++c1; continue; } if (!used[i]) { bip = true; col[i] = 1; dfs(i); if (bip) ++b; ++c; } } cout << c * c + b * b + c1 * (2 * n - c1); //cout << endl; system("pause"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Squared Graph |
User | vjudge4 |
Language | C++14 (GCC 5.4.1) |
Score | 800 |
Code Size | 1356 Byte |
Status | AC |
Exec Time | 78 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 | 2 ms | 2560 KB |
in11.txt | AC | 2 ms | 2560 KB |
in12.txt | AC | 20 ms | 6144 KB |
in13.txt | AC | 20 ms | 6272 KB |
in14.txt | AC | 37 ms | 6272 KB |
in15.txt | AC | 6 ms | 3456 KB |
in16.txt | AC | 28 ms | 4736 KB |
in17.txt | AC | 22 ms | 6016 KB |
in18.txt | AC | 52 ms | 7808 KB |
in19.txt | AC | 41 ms | 7936 KB |
in2.txt | AC | 2 ms | 2560 KB |
in20.txt | AC | 42 ms | 7936 KB |
in21.txt | AC | 77 ms | 11904 KB |
in22.txt | AC | 49 ms | 6272 KB |
in23.txt | AC | 36 ms | 4864 KB |
in24.txt | AC | 3 ms | 3072 KB |
in25.txt | AC | 78 ms | 11904 KB |
in26.txt | AC | 2 ms | 2560 KB |
in27.txt | AC | 3 ms | 2688 KB |
in28.txt | AC | 77 ms | 11904 KB |
in3.txt | AC | 2 ms | 2560 KB |
in4.txt | AC | 2 ms | 2688 KB |
in5.txt | AC | 51 ms | 5760 KB |
in6.txt | AC | 5 ms | 3456 KB |
in7.txt | AC | 5 ms | 3328 KB |
in8.txt | AC | 9 ms | 3968 KB |
in9.txt | AC | 24 ms | 5504 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |