답안 #779158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779158 2023-07-11T08:34:46 Z andrej246 슈퍼트리 잇기 (IOI20_supertrees) C++14
0 / 100
1 ms 468 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,N) for(long long i = 0; (i) < (N); (i)++)
#define FORS(i,v,N) for(long long i = v; (i) < (N); (i)++)
#define FORI(i,v,N,inc) for(long long i = v; (i) < (N); (i)+=(inc))

#define NL '\n'
#define EL cout << NL

#define PRINTV(v) for(auto a:(v)) {cout << a << " ";};EL
#define PRINTVV(v) for(auto a:(v)) {PRINTV(a);}

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VLL;
typedef pair<ll,ll> PL;
typedef vector<PL> VPL;
typedef vector<VPL> VVPL;

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	vector<bool> visited(n,0);
	FOR(s,n) {
		if (!visited[s]) {
			vector<int> branch;
			vector<int> cycle;
			vector<bool> incycle(n,false);
			stack<int> st;
			st.push(s);
			while(!st.empty()) {
				int u = st.top();
				st.pop();
				if (visited[u]) continue;
				visited[u] = true;
				bool is_cycle = true;
				FOR(v,n) {
					if (v == u) continue;
					if (p[u][v] >= 1) {
                        is_cycle = is_cycle && (p[u][v] == 2);
						st.push(v);
					}
				}
				if (is_cycle)  {
					cycle.push_back(u);
					incycle[u] = true;
				}
				else branch.push_back(u);
			}
			//PRINTV(branch);
			//PRINTV(cycle);
			assert(0);
			for (auto u: branch) {
				FOR(v,n) {
					if (p[u][v] == 2 && !incycle[v]) {
                        return 0;
					}
				}
			}
			int prev_u = -1;
			for(auto u: branch) {
				if (prev_u >= 0) {
                    answer[u][prev_u] = answer[prev_u][u] = 1;
				}
				prev_u = u;
			}
			int prev_v = prev_u;
			for (auto v: cycle) {
				answer[v][prev_v] = answer[prev_v][v] = 1;
				prev_v = v;
			}
			if (prev_v != prev_u) answer[prev_u][prev_v] = answer[prev_v][prev_u] = 1;
		}
	}
	build(answer);
	return 1;
}

# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -