답안 #223741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223741 2020-04-16T09:23:40 Z staniewzki 낙하산 고리들 (IOI12_rings) C++17
38 / 100
4000 ms 49076 KB
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for(int i = 0; i < n; i++)
 
template<class T> int size(T && a) { return (int) a.size(); }
 
struct Graph {
	vector<int> rep, deg;
	int excluded = -1;
 
	int find(int x) {
		return rep[x] < 0 ? x : find(rep[x]);
	}
 
	int bicomp = -1;
	int get_cycle() {
		return -rep[find(bicomp)];
	}
 
	void join(int x, int y) {
		x = find(x), y = find(y);
		if(x == y) {
			if(bicomp == -1) bicomp = x;
			else bicomp = -2;
			return;
		}
		rep[x] += rep[y];
		rep[y] = x;
	}
 
	int max_deg = 0;
	void add_edge(int a, int b) {
		if(a == excluded || b == excluded)
			return;
		max_deg |= 3 <= ++deg[a];
		max_deg |= 3 <= ++deg[b];
		join(a, b);
	}
 
	Graph(int n = 0, int e = -1) : rep(n, -1), deg(n), excluded(e) {}
};
 
int n;
vector<pair<int, int>> edges;
Graph graph;
vector<Graph> without;
 
void Init(int N) {
	n = N;
	graph = Graph(n);
}
 
void Link(int A, int B) {
	edges.emplace_back(A, B);
	if(!graph.max_deg) {
		graph.add_edge(A, B);
		if(graph.max_deg) {
			if(graph.deg[A] != 3)
				swap(A, B);
 
			vector<int> crit = {A};
			for(auto &[u, v] : edges) {
				if(u == A) crit.emplace_back(v);
				if(v == A) crit.emplace_back(u);
			}
 
			for(int x : crit) {
				without.emplace_back(n, x);
				for(auto &[u, v] : edges)
					without.back().add_edge(v, u);		
			}
		}
	}
	else {
		for(auto &g : without)
			g.add_edge(A, B);
	}
}
 
int CountCritical() {
	if(!graph.max_deg) {
		if(graph.bicomp == -1) return n;
		if(graph.bicomp == -2) return 0;
		return graph.get_cycle();
	}
	else {
		int ret = 0;
		for(auto &g : without) {
			if(g.bicomp == -1 && !g.max_deg)
				ret++;
		}
		return ret;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 9708 KB Output is correct
2 Correct 666 ms 41060 KB Output is correct
3 Execution timed out 4078 ms 49076 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 6 ms 640 KB Output is correct
12 Correct 9 ms 1024 KB Output is correct
13 Correct 10 ms 1024 KB Output is correct
14 Correct 41 ms 896 KB Output is correct
15 Correct 75 ms 1280 KB Output is correct
16 Correct 8 ms 768 KB Output is correct
17 Correct 9 ms 1024 KB Output is correct
18 Correct 9 ms 1408 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 8 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 6 ms 640 KB Output is correct
12 Correct 9 ms 1024 KB Output is correct
13 Correct 10 ms 1024 KB Output is correct
14 Correct 41 ms 896 KB Output is correct
15 Correct 75 ms 1280 KB Output is correct
16 Correct 8 ms 768 KB Output is correct
17 Correct 9 ms 1024 KB Output is correct
18 Correct 9 ms 1408 KB Output is correct
19 Correct 8 ms 768 KB Output is correct
20 Correct 8 ms 1024 KB Output is correct
21 Correct 19 ms 1664 KB Output is correct
22 Correct 27 ms 2432 KB Output is correct
23 Correct 33 ms 2804 KB Output is correct
24 Execution timed out 4070 ms 5796 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 6 ms 768 KB Output is correct
11 Correct 196 ms 9708 KB Output is correct
12 Correct 666 ms 41060 KB Output is correct
13 Execution timed out 4078 ms 49076 KB Time limit exceeded
14 Halted 0 ms 0 KB -