제출 #517011

#제출 시각아이디문제언어결과실행 시간메모리
517011shmad철인 이종 경기 (APIO18_duathlon)C++17
34 / 100
1091 ms46040 KiB
#pragma GCC optimize("O3", "unroll-loops") #pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") #include <bits/stdc++.h> #define int long long #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define ff first #define ss second #define dbg(x) cerr << #x << " = " << x << '\n' using namespace std; using ll = long long; using pii = pair<int, int>; using vvi = vt< vt<int> >; const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60); const double eps = 1e-6; int n, m, sz; vt<int> g[N], used(N), col(N); bool ok, cycle; void dfs (int v, int s, int c, int f, bool check = 0) { used[v] = 1; if (v == f) { ok |= check; return; } if (ok) return; if (v == c) check = 1; for (auto to: g[v]) { if (!used[to]) { dfs(to, s, c, f, check); used[to] = 0; } } } void dfs (int v, int p = -1) { col[v] = 1; sz++; for (auto to: g[v]) { if (to != p) { if (col[to] == 1) cycle = 1; if (col[to] == 0) dfs(to, v); } } col[v] = 2; } void solve_1 () { int ans = 0; used.resize(200); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { if (i == j || i == k || j == k) continue; ok = 0; fill(all(used), 0); dfs(i, i, j, k); if (ok) ans++; } } } cout << ans << '\n'; } bool cum[51][51][51]; void paint (int v, int p, int colour) { col[v] = colour; for (auto to : g[v]) { if (to != p && !col[to]) paint(to, p, colour); } } void solve_2 () { int ans = 0; for (int p = 1; p <= n; p++) { fill(all(col), 0); int colour = 0; for (int v = 1; v <= n; v++) { if (v != p && !col[v]) paint(v, p, ++colour); } for (int s = 1; s <= n; s++) { for (int c = 1; c <= n; c++) { if (c == p || col[c] == col[s]) continue; for (int f = 1; f <= n; f++) { if (f == s || col[f] == col[c] || cum[s][f][c]) continue; ans--; cum[s][f][c] = 1; } } } } ans += (n * (n - 1) * (n - 2)); cout << ans << '\n'; } void solve_3 () { int ans = 0; for (int i = 1; i <= n; i++) { if (!col[i]) { sz = cycle = 0; dfs(i); int x = sz * (sz - 1) * (sz - 2); if (!cycle) x /= 3; ans += x; } } cout << ans << '\n'; } void solve_4 () { int ans = 0; for (int s = 1; s <= n; s++) { queue<int> q; vt<int> d(n + 1, inf); q.push(s); d[s] = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (auto to: g[v]) { if (d[to] > d[v] + 1) { d[to] = d[v] + 1; q.push(to); } } } for (int i = 1; i <= n; i++) { if (i != s && d[i] != inf) ans += d[i] - 1; } } cout << ans << '\n'; } void solve () { cin >> n >> m; bool sub1 = (n <= 10 && m <= 100), sub2 = (n <= 50 && m <= 100), sub3 = 1; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; g[x].pb(y); g[y].pb(x); if (max(sz(g[x]), sz(g[y])) > 2) sub3 = 0; } if (sub1) { solve_1(); return; } if (sub2) { solve_2(); return; } if (sub3) { solve_3(); return; } solve_4(); cout << '\n'; } bool testcases = 0; signed main() { #ifdef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif cin.tie(0) -> sync_with_stdio(0); int test = 1; if (testcases) cin >> test; for (int cs = 1; cs <= test; cs++) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...