# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
131542 | dndhk | 산만한 고양이 (KOI17_cat) | C++14 | 460 ms | 40056 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 300000;
int N, M;
vector<int> gp[MAX_N+1];
int lv[MAX_N+1], p[MAX_N+1], C[MAX_N+1], up[MAX_N+1];
bool vst[MAX_N+1];
bool chk[MAX_N+1];
ll ans;
void dfs(int x){
vst[x] = chk[x] = true;
for(int i=0; i<gp[x].size(); i++){
if(gp[x][i]==p[x]) continue;
if(vst[gp[x][i]]){
if(lv[x]>lv[gp[x][i]]){C[x]++; up[gp[x][i]]++;}
continue;
}
lv[gp[x][i]] = lv[x]+1; p[gp[x][i]] = x;
dfs(gp[x][i]); C[x] += C[gp[x][i]];
if(C[gp[x][i]] - up[x] > 1) chk[x] = false;
if(up[x]>0) chk[p[x]] = false;
up[p[x]]+=up[x]; up[x] = 0;
}
if(chk[x] && C[x]==M) ans+=(ll)x;
}
int main(){
scanf("%d%d", &N, &M);
for(int i=0; i<M; i++){
int a, b; scanf("%d%d", &a, &b);
gp[a].pb(b); gp[b].pb(a);
}
M -= (N-1);
lv[1] = 1; dfs(1);
cout<<ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |