Submission #1370421
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], cycle; void dfs(int x, int p = -1) { u[x] = 1; for (auto it : v[x]) { if (it == p) continue; if (!u[it]) dfs(it, x); else if (u[it] == 1) { cycle = 1; } } u[x] = 2; } int deg[N]; 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; vector<pii> e; while (m--) { int x, y; cin >> x >> y; --x, --y; e.pb({x, y}); e.pb({y, x}); v[x].pb(y); v[y].pb(x); ++deg[x]; ++deg[y]; } /* for (int i = 0; i < sz(e); i++) { for (int j = 0; j < sz(e); j++) { v[e[i].f * n + e[j].f].pb(e[i].s * n + e[j].s); } } */ ll comp = 0, diger = 0, cnt = 0; for (int i = 0; i < n; i++) { if (!deg[i]) { comp += n + n - 1; } else if (!u[i]) { cycle = 0; dfs(i); ++diger; //diger = 2 - cycle; //comp += 2 * diger - 1; } } //cout << diger << endl; cout << comp + 2 + (diger - 1) * 3; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Squared Graph |
User | Nurlykhan |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1952 Byte |
Status | WA |
Exec Time | 161 ms |
Memory | 13676 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 | 2 ms | 2560 KB |
in11.txt | WA | 2 ms | 2560 KB |
in12.txt | WA | 43 ms | 7284 KB |
in13.txt | WA | 41 ms | 7284 KB |
in14.txt | WA | 79 ms | 8048 KB |
in15.txt | WA | 9 ms | 3840 KB |
in16.txt | WA | 59 ms | 6516 KB |
in17.txt | WA | 44 ms | 6900 KB |
in18.txt | WA | 111 ms | 11120 KB |
in19.txt | WA | 82 ms | 8944 KB |
in2.txt | WA | 2 ms | 2560 KB |
in20.txt | WA | 94 ms | 8944 KB |
in21.txt | WA | 161 ms | 13676 KB |
in22.txt | WA | 117 ms | 10480 KB |
in23.txt | WA | 97 ms | 8688 KB |
in24.txt | WA | 3 ms | 3456 KB |
in25.txt | WA | 157 ms | 13420 KB |
in26.txt | WA | 2 ms | 2560 KB |
in27.txt | WA | 3 ms | 2688 KB |
in28.txt | WA | 157 ms | 13420 KB |
in3.txt | WA | 2 ms | 2560 KB |
in4.txt | WA | 2 ms | 2560 KB |
in5.txt | WA | 119 ms | 9456 KB |
in6.txt | WA | 7 ms | 3712 KB |
in7.txt | WA | 8 ms | 3712 KB |
in8.txt | WA | 16 ms | 4476 KB |
in9.txt | WA | 47 ms | 6260 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |