답안 #5983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5983 2014-06-08T12:48:51 Z model_code 전압 (JOI14_voltage) C++
100 / 100
104 ms 12880 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>

using namespace std;

const int LIM_N = 100000;
const int LIM_M = 200000;

int N, M;
int A[LIM_M + 10], B[LIM_M + 10];

int m, ptr[LIM_N + 10], next[LIM_M * 2 + 10], zu[LIM_M * 2 + 10];
int ips[LIM_N + 10], depths[LIM_N + 10];
int badCnt, goodCnt;
int bad[LIM_N + 10], good[LIM_N + 10];

void dfs0(int u, int ip, int depth) {
	int i, v;
	ips[u] = ip;
	depths[u] = depth;
	for (i = ptr[u]; ~i; i = next[i]) if ((i ^ 1) != ip) {
		v = zu[i];
		if (!~depths[v]) {
			//	tree edge
			dfs0(v, i, depth + 1);
		} else if (depths[u] > depths[v]) {
			//	back edge
			if (depths[u] % 2 == depths[v] % 2) {
				++badCnt;
				++bad[u];
				--bad[v];
			} else {
				++goodCnt;
				++good[u];
				--good[v];
			}
		}
	}
}

void dfs1(int u, int ip) {
	int i, v;
	for (i = ptr[u]; ~i; i = next[i]) if ((i ^ 1) != ip) {
		v = zu[i];
		if (i == ips[v]) {
			dfs1(v, i);
			bad[u] += bad[v];
			good[u] += good[v];
		}
	}
}

int main() {
	int i, u;
	
	for (; ~scanf("%d%d", &N, &M); ) {
		for (i = 0; i < M; ++i) {
			scanf("%d%d", &A[i], &B[i]);
			--A[i];
			--B[i];
		}
		m = 0;
		memset(ptr, ~0, N * 4);
		for (i = 0; i < M; ++i) {
			next[m] = ptr[A[i]]; ptr[A[i]] = m; zu[m] = B[i]; ++m;
			next[m] = ptr[B[i]]; ptr[B[i]] = m; zu[m] = A[i]; ++m;
		}
		
		memset(ips, ~0, N * 4);
		memset(depths, ~0, N * 4);
		badCnt = 0;
		goodCnt = 0;
		memset(bad, 0, N * 4);
		memset(good, 0, N * 4);
		for (u = 0; u < N; ++u) if (!~depths[u]) {
			dfs0(u, -1, 0);
		}
		for (u = 0; u < N; ++u) if (!~ips[u]) {
			dfs1(u, -1);
		}
		
		int ans = 0;
		//	tree edge
		for (u = 0; u < N; ++u) if (~ips[u]) {
			if (bad[u] == badCnt && good[u] == 0) {
				++ans;
			}
		}
		//	back edge
		if (badCnt == 1) {
			++ans;
		}
		printf("%d\n", ans);
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8316 KB Output is correct
2 Correct 0 ms 8316 KB Output is correct
3 Correct 0 ms 8316 KB Output is correct
4 Correct 0 ms 8316 KB Output is correct
5 Correct 0 ms 8316 KB Output is correct
6 Correct 0 ms 8316 KB Output is correct
7 Correct 0 ms 8316 KB Output is correct
8 Correct 0 ms 8316 KB Output is correct
9 Correct 0 ms 8316 KB Output is correct
10 Correct 0 ms 8316 KB Output is correct
11 Correct 0 ms 8316 KB Output is correct
12 Correct 0 ms 8316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 8316 KB Output is correct
2 Correct 44 ms 10900 KB Output is correct
3 Correct 32 ms 8316 KB Output is correct
4 Correct 40 ms 11872 KB Output is correct
5 Correct 4 ms 8352 KB Output is correct
6 Correct 40 ms 9708 KB Output is correct
7 Correct 48 ms 12876 KB Output is correct
8 Correct 44 ms 12880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 8316 KB Output is correct
2 Correct 28 ms 12880 KB Output is correct
3 Correct 24 ms 12880 KB Output is correct
4 Correct 0 ms 8316 KB Output is correct
5 Correct 36 ms 10448 KB Output is correct
6 Correct 40 ms 8316 KB Output is correct
7 Correct 32 ms 10304 KB Output is correct
8 Correct 48 ms 10840 KB Output is correct
9 Correct 36 ms 11096 KB Output is correct
10 Correct 44 ms 9912 KB Output is correct
11 Correct 32 ms 8316 KB Output is correct
12 Correct 40 ms 9768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 8316 KB Output is correct
2 Correct 48 ms 12876 KB Output is correct
3 Correct 0 ms 8316 KB Output is correct
4 Correct 48 ms 10944 KB Output is correct
5 Correct 44 ms 11412 KB Output is correct
6 Correct 52 ms 10564 KB Output is correct
7 Correct 88 ms 10876 KB Output is correct
8 Correct 104 ms 11608 KB Output is correct
9 Correct 88 ms 9564 KB Output is correct
10 Correct 96 ms 11196 KB Output is correct
11 Correct 96 ms 9736 KB Output is correct
12 Correct 96 ms 11220 KB Output is correct
13 Correct 72 ms 9304 KB Output is correct
14 Correct 92 ms 11308 KB Output is correct
15 Correct 96 ms 11248 KB Output is correct
16 Correct 88 ms 10348 KB Output is correct
17 Correct 104 ms 9940 KB Output is correct
18 Correct 76 ms 10112 KB Output is correct