Submission #1201697

#TimeUsernameProblemLanguageResultExecution timeMemory
1201697crispxx철인 이종 경기 (APIO18_duathlon)C++20
10 / 100
1096 ms8204 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() #define pb push_back #define ar array #define nl '\n' template <typename A, typename B> bool chmin(A &a, const B &b) { if(a > b) { return a = b, true; } return false; } template <typename A, typename B> bool chmax(A &a, const B &b) { if(a < b) { return a = b, true; } return false; } void solve() { int n, m; cin >> n >> m; vector<vector<int>> adj(n); for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[--u].pb(--v); adj[v].pb(u); } int ans = 0; for(int u = 0; u < n; u++) { queue<int> q; vector<int> d(n, -1), sum(n); q.emplace(u); d[u] = 0; while(!q.empty()) { int v = q.front(); q.pop(); ans += sum[v]; for(auto to : adj[v]) { if(d[to] == -1) { d[to] = d[v] + 1; sum[to] += d[v]; q.emplace(to); } } } } cout << ans << nl; } /** 4 3 1 2 2 3 3 4 4 4 1 2 2 3 3 4 4 2 **/ signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); 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...