Submission #821335

#TimeUsernameProblemLanguageResultExecution timeMemory
821335danikoynovMarshmallow Molecules (CCO19_day2problem2)C++14
0 / 25
60 ms7348 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 5010; int n, m; ll len[maxn]; bitset < maxn > edge[maxn]; vector < int > adj[100010]; void solve() { cin >> n >> m; /**if (n <= 5000) { for (int i = 1; i <= m; i ++) { int a, b; cin >> a >> b; edge[a][b] = 1; } int ans = 0; for (int i = 1; i <= n; i ++) { for (int j = 1; j <= i; j ++) { edge[i][j] = 0; } for (int j = i + 1; j <= n; j ++) { if (edge[i][j] == 1) { edge[j] |= edge[i]; } } } for (int i = 1; i <= n; i ++) { edge[i][i] = 0; ans += edge[i].count(); } cout << ans << endl; } else*/ { for (int i = 1; i <= m; i ++) { int a, b; cin >> a >> b; adj[a].push_back(b); } ll all_edges = m; for (int i = n; i > 0; i --) { ll sum = 0; ///cout << "vertex " << i << endl; for (int u : adj[i]) { sum += len[u]; } ///cout << sum << endl; all_edges += max(0, (int)(adj[i].size()) - 1); all_edges += max((ll)0, sum - 1); for (int u : adj[i]) { //all_edges += (len[u]) * (sum - len[u]); //sum -= len[u]; len[i] += len[u]; } len[i] ++; } cout << all_edges << endl; } } int main() { solve(); return 0; } /** 5 3 1 2 1 3 3 4 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...