이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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 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... |