이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[300005];
int root = 1;
int rootChild = 0;
int parts[300005];
int low[300005];
int depth[300005];
int p[300005];
void tarjan(int u){
low[u] = depth[u];
for(int v : adj[u]){
if(depth[v] == 0){
depth[v] = depth[u] + 1;
if(u == root) rootChild++;
p[v] = u;
tarjan(v);
if(low[v] > depth[u]) parts[u]++;
low[u] = min(low[u], low[v]);
}
if(v != p[u]){
low[u] = min(low[u], depth[v]);
}
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m; cin >> n >> m;
for(int i = 0;i < m;i++){
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
assert(a != b);
}
depth[root] = 1;
tarjan(root);
for(int i = 2;i <= n;i++) parts[i]++;
parts[root] = rootChild;
long long ans = 0;
for(int i = 1;i <= n;i++){
int target = (n - 1) - parts[i];
int leftEdges = m - (int) adj[i].size();
if(target == leftEdges){
ans += i;
}
}
cout << ans;
}
# | 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... |