Submission #25754

# Submission time Handle Problem Language Result Execution time Memory
25754 2017-06-24T04:45:50 Z 도토리(#1084) 전압 (JOI14_voltage) C++14
100 / 100
276 ms 18036 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);
                           ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7332 KB Output is correct
2 Correct 3 ms 7200 KB Output is correct
3 Correct 3 ms 7200 KB Output is correct
4 Correct 3 ms 7200 KB Output is correct
5 Correct 0 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 0 ms 7332 KB Output is correct
11 Correct 0 ms 7332 KB Output is correct
12 Correct 0 ms 7332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 12968 KB Output is correct
2 Correct 86 ms 15032 KB Output is correct
3 Correct 79 ms 12964 KB Output is correct
4 Correct 129 ms 16004 KB Output is correct
5 Correct 13 ms 7920 KB Output is correct
6 Correct 119 ms 13900 KB Output is correct
7 Correct 136 ms 17016 KB Output is correct
8 Correct 119 ms 17012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 12968 KB Output is correct
2 Correct 56 ms 17016 KB Output is correct
3 Correct 39 ms 17016 KB Output is correct
4 Correct 0 ms 7200 KB Output is correct
5 Correct 96 ms 14036 KB Output is correct
6 Correct 116 ms 12564 KB Output is correct
7 Correct 129 ms 14444 KB Output is correct
8 Correct 143 ms 15472 KB Output is correct
9 Correct 136 ms 15252 KB Output is correct
10 Correct 116 ms 14244 KB Output is correct
11 Correct 123 ms 12564 KB Output is correct
12 Correct 133 ms 13532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 14504 KB Output is correct
2 Correct 89 ms 18036 KB Output is correct
3 Correct 3 ms 8820 KB Output is correct
4 Correct 139 ms 14968 KB Output is correct
5 Correct 156 ms 15740 KB Output is correct
6 Correct 136 ms 14824 KB Output is correct
7 Correct 239 ms 16456 KB Output is correct
8 Correct 236 ms 16924 KB Output is correct
9 Correct 246 ms 15520 KB Output is correct
10 Correct 266 ms 17412 KB Output is correct
11 Correct 183 ms 15704 KB Output is correct
12 Correct 263 ms 17424 KB Output is correct
13 Correct 189 ms 15232 KB Output is correct
14 Correct 226 ms 17972 KB Output is correct
15 Correct 276 ms 17452 KB Output is correct
16 Correct 223 ms 17076 KB Output is correct
17 Correct 239 ms 15980 KB Output is correct
18 Correct 153 ms 16684 KB Output is correct