답안 #25755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25755 2017-06-24T04:59:34 Z dotorya 전압 (JOI14_voltage) C++14
100 / 100
276 ms 18040 KB
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

class edge {
public:
	int s, e;
	edge() {
		*this = edge(0, 1);
	}
	edge(int s, int e) : s(s), e(e) {}
};
vector <edge> Ve;
vector <int> conn[100050];
void epush(int a, int b) {
	conn[a].push_back(Ve.size());
	conn[b].push_back(Ve.size());
	Ve.emplace_back(a, b);
}

vector <int> Vv;
int par[100050];
int dep[100050];
bool dchk[100050];
int lr[100050][2];
int tus = 0;
void DFS(int n) {
	Vv.push_back(n);
	dchk[n] = true;
	lr[n][0] = ++tus;
	for (auto it : conn[n]) {
		int n2 = Ve[it].s + Ve[it].e - n;
		if (dchk[n2]) continue;
		par[n2] = it;
		dep[n2] = dep[n] + 1;
		DFS(n2);
	}
	lr[n][1] = tus;
}

int bit[300000];
void update(int p, int v) {
	for (; p <= IT_MAX; p += p & (-p)) bit[p] += v;
}
int getsum(int p) {
	int rv = 0;
	for (; p; p -= p & (-p)) rv += bit[p];
	return rv;
}

vector <pii> Va;
int main() {
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		epush(t1, t2);
	}
	for (i = 1; i <= N; i++) {
		if (dchk[i]) continue;
		par[i] = -1;
		tus = 0;
		Vv.clear();
		DFS(i);

		for (IT_MAX = 2; IT_MAX < Vv.size(); IT_MAX *= 2);
		for (j = 1; j <= IT_MAX; j++) bit[j] = 0;
		int c1 = 0;
		for (auto n1 : Vv) {
			for (auto it : conn[n1]) {
				int n2 = Ve[it].s + Ve[it].e - n1;
				if (dep[n1] > dep[n2]) continue;
				if (par[n2] == it) continue;
				if (dep[n1] % 2 == dep[n2] % 2) {
					c1++;
					update(lr[n2][0], 1);
					update(lr[n1][0], -1);
				}

				else {
					update(lr[n2][0], -1);
					update(lr[n1][0], 1);
				}
			}
		}

		int ans = 0;
		if (c1 == 1) ans++;
		for (auto it : Vv) if (it != i && getsum(lr[it][1]) - getsum(lr[it][0] - 1) == c1) ans++;
		Va.emplace_back(ans, !!c1);
	}

	int c = 0;
	for (auto it : Va) c += it.second;
	if (c >= 2) return !printf("0\n");

	int t = 0;
	for (auto it : Va) if (it.second == c) t += it.first;
	return !printf("%d\n", t);
}

Compilation message

voltage.cpp:23:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)  
 ^
voltage.cpp:24:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:336777216")  
 ^
voltage.cpp: In function 'int main()':
voltage.cpp:115:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (IT_MAX = 2; IT_MAX < Vv.size(); IT_MAX *= 2);
                           ^
voltage.cpp:102:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
                        ^
voltage.cpp:105:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &t1, &t2);
                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7332 KB Output is correct
2 Correct 0 ms 7200 KB Output is correct
3 Correct 0 ms 7200 KB Output is correct
4 Correct 0 ms 7200 KB Output is correct
5 Correct 3 ms 7332 KB Output is correct
6 Correct 0 ms 7332 KB Output is correct
7 Correct 3 ms 7332 KB Output is correct
8 Correct 3 ms 7332 KB Output is correct
9 Correct 3 ms 7332 KB Output is correct
10 Correct 3 ms 7332 KB Output is correct
11 Correct 3 ms 7332 KB Output is correct
12 Correct 3 ms 7332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 12968 KB Output is correct
2 Correct 129 ms 15036 KB Output is correct
3 Correct 79 ms 12964 KB Output is correct
4 Correct 123 ms 16008 KB Output is correct
5 Correct 6 ms 7920 KB Output is correct
6 Correct 109 ms 13904 KB Output is correct
7 Correct 129 ms 17016 KB Output is correct
8 Correct 129 ms 17016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 12968 KB Output is correct
2 Correct 46 ms 17016 KB Output is correct
3 Correct 33 ms 17012 KB Output is correct
4 Correct 0 ms 7200 KB Output is correct
5 Correct 99 ms 14032 KB Output is correct
6 Correct 99 ms 12564 KB Output is correct
7 Correct 119 ms 14440 KB Output is correct
8 Correct 129 ms 15472 KB Output is correct
9 Correct 123 ms 15252 KB Output is correct
10 Correct 93 ms 14244 KB Output is correct
11 Correct 136 ms 12564 KB Output is correct
12 Correct 136 ms 13536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 14504 KB Output is correct
2 Correct 93 ms 18040 KB Output is correct
3 Correct 3 ms 8820 KB Output is correct
4 Correct 126 ms 14972 KB Output is correct
5 Correct 153 ms 15744 KB Output is correct
6 Correct 73 ms 14824 KB Output is correct
7 Correct 149 ms 16452 KB Output is correct
8 Correct 133 ms 16924 KB Output is correct
9 Correct 209 ms 15520 KB Output is correct
10 Correct 276 ms 17412 KB Output is correct
11 Correct 246 ms 15704 KB Output is correct
12 Correct 256 ms 17428 KB Output is correct
13 Correct 196 ms 15228 KB Output is correct
14 Correct 239 ms 17972 KB Output is correct
15 Correct 229 ms 17452 KB Output is correct
16 Correct 213 ms 17072 KB Output is correct
17 Correct 226 ms 15980 KB Output is correct
18 Correct 183 ms 16680 KB Output is correct