#include <bits/stdc++.h>
using namespace std;
int n, m, nodes, vid, found;
vector<vector<int>> adj;
vector<int> vis, stck;
set<int> st;
long long ans;
void dfs (int u, int k) {
if (found) {
return;
}
vis[u] = vid;
if (u == k) {
for (int v : stck) {
st.insert(v);
}
}
stck.push_back(u);
for (int v : adj[u]) {
if (vis[v] != vid) {
dfs(v, k);
}
}
stck.pop_back();
vis[u] = 0;
}
int main (){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
adj.resize(n);
while (m--) {
int u, v;
cin >> u >> v, --u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vis.resize(n);
for (int u = 0; u < n; ++u) {
for (int v = 0; v < n; ++v) {
if (u ^ v) {
++vid;
dfs(u, v);
ans += max(0, (int)st.size() - 1);
st.clear();
}
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
304 KB |
Output is correct |
9 |
Correct |
131 ms |
204 KB |
Output is correct |
10 |
Execution timed out |
1095 ms |
204 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
304 KB |
Output is correct |
9 |
Correct |
131 ms |
204 KB |
Output is correct |
10 |
Execution timed out |
1095 ms |
204 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
19188 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
6284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1092 ms |
332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
6272 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
304 KB |
Output is correct |
9 |
Correct |
131 ms |
204 KB |
Output is correct |
10 |
Execution timed out |
1095 ms |
204 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
304 KB |
Output is correct |
9 |
Correct |
131 ms |
204 KB |
Output is correct |
10 |
Execution timed out |
1095 ms |
204 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |