이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
int n,is[N],vis[N],own[N],to[N],self[N],flag1 = 1,flag2 = 1,low[N],tim[N],cnt = 0,can[N],comp[N],cc = 0,have[N],cycle[N];
vector <int> g[N],S,g2[N];
int dfs(int u){
vis[u] = 1;
S.push_back(u);
int ret;
if(own[u] == 0){
ret = 1;
for(int i = 0;i<g[u].size();i++){
int v = g[u][i];
if(vis[v] == 1){
int flag = 0;
for(int j = S.size()-1;j>=0;j--){
if(is[S[j]] == 1){
flag = 1;
break;
}
if(S[j] == v)
break;
}
ret = min(ret,flag);
}else{
ret = min(ret,dfs(v));
}
}
}else{
ret = 0;
for(int i = 0;i<g[u].size();i++){
int v = g[u][i];
if(vis[v] == 1){
int flag = 0;
for(int j = S.size()-1;j>=0;j--){
if(is[S[j]] == 1){
flag = 1;
break;
}
if(S[j] == v)
break;
}
ret = max(ret,flag);
}else{
ret = max(ret,dfs(v));
}
}
}
vis[u] = 0;
S.pop_back();
return ret;
}
void DFS(int u){
low[u] = tim[u] = ++cnt;
vis[u] = 1;
S.push_back(u);
for(int i = 0;i<g[u].size();i++){
int v = g[u][i];
if(tim[v] == -1)
DFS(v);
if(vis[v])
low[u] = min(low[u],low[v]);
}
if(low[u] == tim[u]){
cc++;
int tmpp = 0;
while(1){
int v = S.back(); S.pop_back(); vis[v] = 0;
comp[v] = cc;
tmpp++;
if(v == u) break;
}
if(tmpp > 1)
cycle[cc] = 1;
}
}
int calc(int u){
if(can[u] != -1)
return can[u];
can[u] = 0;
if(cycle[u] == 1 && have[u] == 1)
return can[u] = 1;
for(int i = 0;i<g2[u].size();i++){
can[u] = max(can[u],calc(g2[u][i]));
}
return can[u];
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
std::vector<int> res;
n = a.size();
for(int i = 0;i<n;i++){
is[i] = self[i] = to[i] = 0,vis[i] = 0;
have[i] = cycle[i] =0;
}
for(int i = 0;i<u.size();i++){
g[u[i]].push_back(v[i]);
if(u[i] == v[i])
self[u[i]] = 1;
if(u[i] + 1 == v[i])
to[u[i]] = 1;
}
for(int i = 0;i<n;i++)
is[i] = r[i];
for(int i = 0;i<n;i++){
own[i] = a[i];
if(a[i] != 1)
flag1 = 0;
if(a[i] != 0)
flag2 = 0;
}
if(n <= 15){
return res;
int cnt = 0;
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
vis[j] = 0;
}
cnt++;
res.push_back(dfs(i));
}
}else if(flag1 == 1){
for(int i = 0;i<n;i++){
if(tim[i] == -1)
DFS(i);
}
for(int i = 0;i<n;++i){
for(int j = 0;j<g[i].size();j++){
if(comp[i] != comp[g[i][j]])
g2[comp[i]].push_back(g[i][j]);
}
if(is[i])
have[comp[i]] = 1;
can[i] = -1;
}
for(int i = 0;i<n;i++)
res.push_back(calc(i));
}else{
return res;
if(is[n-1] && self[n-1])
res.push_back(1);
else
res.push_back(0);
for(int i = n-2;i>=0;i--){
if(own[i] == 0){
int ret = 1;
ret = min(ret,((!is[i] && self[i]) ? 0 : 1));
ret = min(ret,((to[i]) ? res.back() : 1));
res.push_back(ret);
}else{
int ret = 0;
ret = max(ret,((is[i] && self[i]) ? 1 : 0));
ret = max(ret,((to[i]) ? res.back() : 0));
res.push_back(ret);
}
}
reverse(res.begin(),res.end());
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
train.cpp: In function 'int dfs(int)':
train.cpp:15:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<g[u].size();i++){
~^~~~~~~~~~~~
train.cpp:34:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<g[u].size();i++){
~^~~~~~~~~~~~
train.cpp: In function 'void DFS(int)':
train.cpp:61:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<g[u].size();i++){
~^~~~~~~~~~~~
train.cpp: In function 'int calc(int)':
train.cpp:87:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<g2[u].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:100:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i<u.size();i++){
~^~~~~~~~~
train.cpp:132:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0;j<g[i].size();j++){
~^~~~~~~~~~~~
# | 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... |