답안 #802064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802064 2023-08-02T09:29:16 Z kirakaminski968 장난감 기차 (IOI17_train) C++17
컴파일 오류
0 ms 0 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<int> adj[5005];
vector<int> exc; 
vector<int> bfs(vector<int> &a, vector<int> &v, int winner){
  vector<int> deg(n); 
  queue<int> q; 
  for(int i = 0;i<n;++i){
    if(exc[i]) continue; 
    for(auto x : adj[i]){
      if(!exc[x]) deg[x]++; 
    }
  }
  for(auto x : v){
    if(deg[x] > 0){
      deg[x] = 0; 
    }
    q.push(x); 
  }
  vector<int> res; 
  while(!q.empty()){
    int u = q.front(); q.pop(); 
    res.push_back(u); 
    for(auto x : adj[u]){
      if(exc[x]) continue; 
      if(a[x] == winner && deg[x] > 0){
        deg[x] = 0; 
        q.push(i); 
      }
      else if(a[x] != winner){
        deg[x]--; 
        if(deg[x] == 0) q.push(x); 
      }
    }
  }
  return res; 
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v){
  n = a.size(); m = u.size(); 
  vector<int> ans(n); 
  for(int i = 0;i<m;++i){
    adj[v[i]].push_back(u[i]); 
  }
  while(true){
    int alive = count(exc.begin(),exc.end(),0); 
    if(alive == 0) break; 
    vector<int> R; 
    for(int i = 0;i<n;++i){
      if(!exc[i] && r[i]) R.push_back(i); 
    }
    R = calc(a,R,1); 
    if(R.size() == alive){
      for(auto x : R){
        exc[x] = 1; 
        ans[x] = 1; 
      }
    }
    else{
      vector<int> rem(n); 
      for(auto x : R) rem[x] = 1; 
      R.clear(); 
      for(int i = 0,i<n;++i){
        if(!exc[i] && !rem[i]) R.push_back(i); 
      }
      R = calc(a,R,0); 
      for(auto x : R){
        exc[i] = 1; 
        ans[i] = 1; 
      }
    }
  }
  return ans; 
}

Compilation message

train.cpp: In function 'std::vector<int> bfs(std::vector<int>&, std::vector<int>&, int)':
train.cpp:30:16: error: 'i' was not declared in this scope
   30 |         q.push(i);
      |                ^
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:53:9: error: 'calc' was not declared in this scope
   53 |     R = calc(a,R,1);
      |         ^~~~
train.cpp:54:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     if(R.size() == alive){
      |        ~~~~~~~~~^~~~~~~~
train.cpp:64:22: error: expected ';' before '<' token
   64 |       for(int i = 0,i<n;++i){
      |                      ^
      |                      ;
train.cpp:64:22: error: expected primary-expression before '<' token
train.cpp:69:13: error: 'i' was not declared in this scope
   69 |         exc[i] = 1;
      |             ^
train.cpp:68:16: warning: unused variable 'x' [-Wunused-variable]
   68 |       for(auto x : R){
      |                ^