Submission #544672

#TimeUsernameProblemLanguageResultExecution timeMemory
544672pokmui9909산만한 고양이 (KOI17_cat)C++17
100 / 100
328 ms47640 KiB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
int N, M;
vector<int> G[300005];
int tn[300005], bn[300005];
int child[300005];
int cnt = 0;
 
void dfs(int n, int p, bool root)
{
    tn[n] = bn[n] = ++cnt;
    for(auto i : G[n])
    {
        if(i == p) continue;
        if(bn[i])
        {
            bn[n] = min(tn[i], bn[n]);
            continue;
        }
        dfs(i, n, 0);
        bn[n] = min(bn[i], bn[n]);
        if(tn[n] <= bn[i]) child[n]++;
    }
    if(root == 0) child[n]++;
}
 
int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
 
    cin >> N >> M;
    for(int i = 1; i <= M; i++)
    {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1, -1, 1);
    ll ans = 0;
    for(int i = 1; i <= N; i++)
    {
        if(N - 1 == M - G[i].size() + child[i])
            ans += i;
    }
    cout << ans;
}

Compilation message (stderr)

cat.cpp: In function 'int main()':
cat.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(N - 1 == M - G[i].size() + child[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...