Submission #658901

#TimeUsernameProblemLanguageResultExecution timeMemory
658901JooDdae산만한 고양이 (KOI17_cat)C++17
100 / 100
500 ms85960 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...