Submission #1352108

#TimeUsernameProblemLanguageResultExecution timeMemory
1352108AndreyToy Train (IOI17_train)C++17
12 / 100
6 ms1348 KiB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 5010;
vector<int> haha[MAXN];
vector<int> yeah[MAXN];

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
    int n = a.size();
    int m = u.size();
    for(int i = 0; i < m; i++) {
        haha[u[i]].push_back(v[i]);
        yeah[v[i]].push_back(u[i]);
    }
    queue<int> idk;
    vector<int> col(n);
    for(int i = 0; i < n; i++) {
        if(r[i]) {
            idk.push(i);
        }
    }
    vector<int> br(n);
    while(!idk.empty()) {
        int x = idk.front();
        col[x] = 1;
        idk.pop();
        for(int v: yeah[x]) {
            br[v]++;
            if(a[v] == 1) {
                if(br[v] == 1) {
                    idk.push(v);
                }
            }
            else {
                if(br[v] == haha[v].size()) {
                    idk.push(v);
                }
            }
        }
    }
    int w;
    for(int i = 0; i < n; i++) {
        if(r[i]) {
            w = i;
        }
    }
    bool yeah = true;
    int z = 0;
    for(int v: haha[w]) {
        if(col[v] == 0) {
            z++;
        }
    }
    if(a[z] == 1) {
        if(z == haha[w].size()) {
            yeah = false;
        }
    }
    else {
        if(z == 1) {
            yeah = false;
        }
    }
    if(!yeah) {
        for(int i = 0; i < n; i++) {
            col[i] = 0;
        }
    }
	return col;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...