이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef EVAL
#include "grader.cpp"
#endif
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define ss second
#define ff first
const int N = 5e3+5;
int n;
vector<pair<int, int>> edges[N];
int used[N], vis[N];
void Init(int nn) { n = nn; }
int last;
void Link(int A, int B) {
edges[A].pb({B, ++last});
edges[B].pb({A, last});
}
bool dfs(int u, int p){
if(vis[u]) return 0;
int cnt = 0;
bool ok = 1;
vis[u] = 1;
for(auto x:edges[u]){
if(used[x.ss] || x.ff == p) continue;
if(cnt) return 0;
cnt++;
ok &= dfs(x.ff, u);
}return ok;
}
int CountCritical(){
memset(used, 0, sizeof used);
int cnt = 0;
for(int i=0;i<n;i++){
for(auto x:edges[i]) used[x.ss] = 1;
vis[i] = 1;
bool ok = 1;
for(int j=0;j<n && ok;j++){
if(!vis[j]){
int cnt = 0;
for(auto x:edges[j]){
if(used[x.ss]) continue;
cnt++;
ok &= dfs(x.ff, j);
}
if(cnt > 2) ok = 0;
}
}
for(auto x:edges[i]) used[x.ss] = 0;
memset(vis, 0, sizeof vis);
cnt += ok;
}
return cnt;
}
/*
7 13
-1
1 2
-1
0 5
-1
2 0
-1
3 2
-1
3 5
-1
4 3
-1
*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |