답안 #427554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427554 2021-06-14T17:03:03 Z markthitrin 장난감 기차 (IOI17_train) C++14
0 / 100
1230 ms 1756 KB
#include "train.h"
#include <vector>
#include <iostream>
int N,M;
std::vector<int> f[5005];
std::vector<int> inv_f[5005];
std::vector<int> ans;
int degree[5005];
int m[5005];
bool come[5005];
bool reachable[5005];
void inv_bfs(std::vector<int>& a,int pos){
    if(come[pos])
        return;
    come[pos] = true;
    for(int q = 0;q<inv_f[pos].size();q++){
        m[inv_f[pos][q]]++;
        if(a[inv_f[pos][q]] == 0 && degree[inv_f[pos][q]] == m[inv_f[pos][q]]){
            inv_bfs(a,inv_f[pos][q]);
        }
        else
            inv_bfs(a,inv_f[pos][q]);
    }
}
void bfs(std::vector<int>& a,int pos){
    if(come[pos])
        reachable[pos] = true;
    else return;
    for(int q = 0 ;q<f[pos].size();q++){
        bfs(a,f[pos][q]);
    }
}
void last_func(std::vector<int> a,int pos){
    if(a[pos] == 0 && m[pos] != degree[pos] && !reachable[pos])
        return;
    if(ans[pos] == 1)
        return;
    ans[pos] = 1;
    for(int q = 0 ;q<inv_f[q].size();q++){
        m[inv_f[pos][q]]++;
        last_func(a,inv_f[pos][q]);
    }
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	N = a.size();
	M = u.size();
    for(int q = 0 ;q<N;q++){
        ans.push_back(0);
    }
	for(int q = 0 ;q<M;q++){
        f[u[q]].push_back(v[q]);
        inv_f[v[q]].push_back(u[q]);
        degree[u[q]]++;
	}
	for(int q = 0;q<N;q++){
        if(r[q]){
            for(int w = 0 ;w<N;w++){
                m[w] = 0;
                come[w] = false;
            }
            inv_bfs(a,q);
        }
	}
	return ans;
    for(int w = 0;w<N;w++){
        m[w] = 0;
    }
	for(int q= 0;q<N;q++){
        if(reachable[q])
            last_func(a,q);
	}
	return ans;
}
/*
2 4
0 1
1 0
0 0
0 1
1 0
1 1
1 1
*/

Compilation message

train.cpp: In function 'void inv_bfs(std::vector<int>&, int)':
train.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int q = 0;q<inv_f[pos].size();q++){
      |                   ~^~~~~~~~~~~~~~~~~~
train.cpp: In function 'void bfs(std::vector<int>&, int)':
train.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int q = 0 ;q<f[pos].size();q++){
      |                    ~^~~~~~~~~~~~~~
train.cpp: In function 'void last_func(std::vector<int>, int)':
train.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int q = 0 ;q<inv_f[q].size();q++){
      |                    ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 183 ms 1348 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 460 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 1752 KB Output is correct
2 Correct 160 ms 1756 KB Output is correct
3 Correct 226 ms 1736 KB Output is correct
4 Incorrect 423 ms 1576 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1230 ms 1372 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1484 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 183 ms 1348 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -