This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
int in[300200], low[300200], cnt;
vector<int> v[300200];
stack<pair<int, int>> st;
vector<vector<pair<int, int>>> bcc;
int dfs(int u, int p){
in[u] = low[u] = ++cnt;
for(auto x : v[u]) if(x != p){
if(in[u] > in[x]) st.push({u, x});
if(in[x]) low[u] = min(low[u], in[x]);
else{
low[u] = min(low[u], dfs(x, u));
if(low[x] >= in[u]){
vector<pair<int, int>> b;
while(st.top() != make_pair(u, x)) b.push_back(st.top()), st.pop();
b.push_back(st.top()), st.pop();
if(b.size() > 1) bcc.push_back(b);
}
}
}
return low[u];
}
int c[300300];
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=m;i++) {
int a, b; cin >> a >> b;
v[a].push_back(b), v[b].push_back(a);
}
dfs(1, 0);
for(auto b : bcc) {
map<int, int> mp;
for(auto [x, y] : b) mp[x]++, mp[y]++;
for(auto [x, y] : mp) if((int)b.size() - y <= (int)mp.size() - 2)
// cout << x << " " << y << "\n";
c[x]++;
}
ll ans = 0;
for(int i=1;i<=n;i++) if(m-(int)v[i].size() <= n-2 && (bcc.empty() || c[i] == bcc.size())) ans += i;
cout << ans;
}
Compilation message (stderr)
cat.cpp: In function 'int main()':
cat.cpp:55:80: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=1;i<=n;i++) if(m-(int)v[i].size() <= n-2 && (bcc.empty() || c[i] == bcc.size())) ans += i;
| ~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |