이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5e5;
int n;
int marc[MAXN];
int pode[MAXN];
int bom[MAXN];
int in[MAXN];
vector<int> ar[MAXN];
vector<int> rev[MAXN];
bool haveCycle(int cur, int ori){
marc[cur] = 1;
for(int i = 0; i < ar[cur].size(); i++){
int viz = ar[cur][i];
if(viz == ori) return true;
if(marc[viz]) continue;
if(pode[viz]) continue;
if(haveCycle(viz, ori)) return true;
}
return false;
}
void dfs(int cur){
marc[cur] = 1;
for(int i = 0; i < rev[cur].size(); i++){
int viz = rev[cur][i];
if(marc[viz]) continue;
dfs(viz);
}
}
vector<int> sub1(std::vector<int> a, std::vector<int> r){
vector<int> w(n, 0);
for(int i = n - 1; i >= 0; i--){
if(ar[i].size() == 2){
if(a[i]){
if(r[i]) w[i] = 1;
else w[i] = w[i + 1];
}
else{
if(r[i]) w[i] = w[i + 1];
else w[i] = 0;
}
}
else if(ar[i][0] == i) w[i] = r[i];
else w[i] = w[i + 1];
}
return w;
}
vector<int> sub2(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v){
vector<int> w(n, 0);
return w;
}
vector<int> sub3(std::vector<int> a, std::vector<int> r){
vector<int> w;
for(int i = 0; i < r.size(); i++){
if(!r[i]) continue;
for(int j = 0; j < r.size(); j++)
marc[j] = 0;
bom[i] = haveCycle(i, i);
}
for(int j = 0; j < n; j++)
marc[j] = 0;
for(int i = 0; i < n; i++)
if(bom[i]) dfs(i);
for(int i = 0; i < n; i++)
w.push_back(marc[i]);
return w;
}
vector<int> sub4(std::vector<int> a, std::vector<int> r){
vector<int> w;
for(int j = 0; j < r.size(); j++)
pode[j] = r[j];
for(int i = 0; i < n; i++){
if(r[i]) continue;
for(int j = 0; j < n; j++)
marc[j] = 0;
bom[i] = haveCycle(i, i);
}
for(int j = 0; j < n; j++)
marc[j] = 0;
for(int i = 0; i < n; i++)
if(bom[i]) dfs(i);
for(int i = 0; i < n; i++)
w.push_back(!marc[i]);
return w;
}
void bfs(int ini, vector<int> a){
marc[ini] = 0;
bom[ini] = 0;
for(int i = 0; i < n; i++)
in[i] = ar[i].size();
queue<int> fila;
fila.push(ini);
while(!fila.empty()){
int cur = fila.front();
fila.pop();
if(cur == ini) continue;
for(int i = 0; i < rev[cur].size(); i++){
int viz = rev[cur][i];
if(marc[viz]) continue;
if(!a[viz]) in[viz]--;
if(!a[viz] && in[viz] != 0) continue;
marc[viz] = 1;
bom[viz] = 1;
fila.push(viz);
}
}
}
vector<int> sub5(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v){
vector<int> w (n, 0);
int especial;
for(int i = 0; i < n; i++)
if(r[i]) especial = i;
bfs(especial, a);
if(!bom[especial]) return w;
for(int i = 0; i < n; i++)
w[i] = bom[i];
return w;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n = a.size();
for(int i = 0; i < u.size(); i++){
ar[u[i]].push_back(v[i]);
rev[v[i]].push_back(u[i]);
}
// if(n <= 15) return sub2(a, r, u, v);
bool flag = true;
for(int i = 0; i < n; i++)
flag &= a[i];
if(flag) return sub3(a, r);
flag = true;
for(int i = 0; i < n; i++)
flag &= !a[i];
if(flag) return sub4(a, r);
int cnt = 0;
for(int i = 0; i < n; i++)
cnt += r[i];
if(cnt == 1) return sub5(a, r, u, v);
return sub1(a, r);
}
컴파일 시 표준 에러 (stderr) 메시지
train.cpp: In function 'bool haveCycle(int, int)':
train.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i = 0; i < ar[cur].size(); i++){
| ~~^~~~~~~~~~~~~~~~
train.cpp: In function 'void dfs(int)':
train.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 0; i < rev[cur].size(); i++){
| ~~^~~~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> sub3(std::vector<int>, std::vector<int>)':
train.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i = 0; i < r.size(); i++){
| ~~^~~~~~~~~~
train.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int j = 0; j < r.size(); j++)
| ~~^~~~~~~~~~
train.cpp: In function 'std::vector<int> sub4(std::vector<int>, std::vector<int>)':
train.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int j = 0; j < r.size(); j++)
| ~~^~~~~~~~~~
train.cpp: In function 'void bfs(int, std::vector<int>)':
train.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 < rev[cur].size(); i++){
| ~~^~~~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:141:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | for(int i = 0; i < u.size(); i++){
| ~~^~~~~~~~~~
train.cpp: In function 'std::vector<int> sub5(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:131:18: warning: 'especial' may be used uninitialized in this function [-Wmaybe-uninitialized]
131 | if(!bom[especial]) return w;
| ~~~~~~~~~~~~^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |