이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<int,int>
const int N = 1e6 + 5;
int n, sz = 0, h[N];
int cycle[6], tried[6] , rem[6], stop = 0, p[N][6], built[2];
pii deg;
vector<int> V[6][N];
void Init(int N_) {
n = N_;
for(int i = 0; i < n; i++) {
for(int t = 0; t < 6; t++) {
p[i][t] = i;
}
}
}
int find(int a, int t) {
return (p[a][t] == a ? p[a][t] : p[a][t] = find(p[a][t], t));
}
void merge(int a,int b, int t) {
a = find(a, t); b = find(b, t);
if(a == b) return;
p[a][t] = b;
return;
}
void dfs(int a, int p) {
if(p == -1) h[a] = 1;
else
h[a] = h[p] + 1;
for(int i = 0; i < V[5][a].size(); i++) {
if(V[5][a][i] == p) continue;
if(sz) return;
if(h[V[5][a][i]]) {
sz = h[a] - h[V[5][a][i]] + 1;
return;
} else dfs(V[5][a][i], a);
}
}
void add(int a, int b, int t) {
if(a == rem[t] || b == rem[t]) return;
V[t][a].push_back(b); V[t][b].push_back(a);
tried[t] = max(tried[t], max((int)V[t][a].size(),(int)V[t][b].size()));
if(find(a, t) == find(b, t)) cycle[t] = 1;
else merge(a, b, t);
return;
}
void Link(int a, int b) {
if(stop) return;
V[5][a].push_back(b); V[5][b].push_back(a);
deg = max(deg, {(int)V[5][a].size(), a});
deg = max(deg, {(int)V[5][b].size(), b});
if(find(a, 5) != find(b, 5)) {
merge(a, b, 5);
}
else {
if(!cycle[5]) {
merge(a, b, 5);
dfs(a, -1);
cycle[5] = a + 1;
}
else if(find(a, 5) != find(cycle[5] - 1, 5)) {
stop = 1;
}
}
if(built[0]) {
add(a, b, 0);
}
if(built[1]) {
for(int i = 1; i <= 4; i++) add(a, b, i);
}
}
void build(int t) {
int u = rem[t];
for(int i = 0; i < n; i++) {
if(u == i) continue;
for(int j = 0; j < V[5][i].size(); j++) {
int v = V[5][i][j];
if(v == u || v < i) continue;
if(find(v, t) == find(i, t)) cycle[t] = 1;
merge(i, v, t);
V[t][i].push_back(v); V[t][v].push_back(i);
}
}
for(int i = 0; i < n; i++) tried[t] = max(tried[t], (int)V[t][i].size());
}
int CountCritical() {
if(stop) return 0;
if(!cycle[5] && deg.f <= 2) return n;
if(deg.f <= 2) return sz;
if(deg.f >= 4) {
if(!built[0]) {
built[0] = 1;
rem[0] = deg.s;
build(0);
}
if(tried[0] <= 2 && !cycle[0]) return 1;
stop = 1;
return 0;
}
if(!built[1]) {
built[1] = 1;
rem[1] = deg.s;
if(V[5][rem[1]].size() != 3) {
return 342432;
}
for(int i = 0; i < V[5][rem[1]].size(); i++) {
rem[i + 2] = V[5][rem[1]][i];
}
for(int i = 1; i <= 4; i++) {
build(i);
}
}
int cn = 0;
for(int i = 1; i <= 4; i++) {
if(tried[i] <= 2 && !cycle[i]) cn++;
}
if(!cn) stop = 1;
return cn;
}
컴파일 시 표준 에러 (stderr) 메시지
rings.cpp: In function 'void dfs(int, int)':
rings.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < V[5][a].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
rings.cpp: In function 'void build(int)':
rings.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int j = 0; j < V[5][i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~
rings.cpp: In function 'int CountCritical()':
rings.cpp:110:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i = 0; i < V[5][rem[1]].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |