Submission #820980

#TimeUsernameProblemLanguageResultExecution timeMemory
820980danikoynovMarshmallow Molecules (CCO19_day2problem2)C++14
10 / 25
781 ms4312 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; bitset < maxn > edge[maxn]; void solve() { cin >> n >> m; 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(); } /**for (int i = 1; i <= n; i ++, cout << endl) for (int j = 1; j <= n; j ++) cout << edge[i][j] << " ";*/ cout << ans << endl; } int main() { solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...