Submission #263617

#TimeUsernameProblemLanguageResultExecution timeMemory
263617arayiToy Train (IOI17_train)C++17
100 / 100
1474 ms4088 KiB
#include "train.h"
#include <vector>
#include <queue>
#include <algorithm>
#define ad push_back
using namespace std;

const int N = 5e4 + 30;

int n;
vector <int> g[N], g1[N];
vector<int> col, r;
int sm[N], need[N];
void smth()
{
    for (int i = 0; i < n; i++)
	    sm[i] = 0, col[i] = 0;
    queue <int> q;
    for (int i = 0; i < n; i++)
	{
        if(r[i])
        {
            for(auto p : g1[i])
            {
                sm[p]++;
                if(sm[p] == need[p]) q.push(p);
            }
        }
	}
	while(!q.empty())
    {
        int v = q.front();
        q.pop();
        col[v] = 1;
        if(r[v]) continue;
        for(auto p : g1[v])
        {
            sm[p]++;
            if(sm[p] == need[p]) q.push(p);
        }
    }
}
vector <int> who_wins(vector<int> a, vector<int> R, vector<int> u, vector<int> v) {
	n = a.size();
	r = R;
	for (int i = 0; i < u.size(); i++)
	{
	    g[u[i]].ad(v[i]);
	    g1[v[i]].ad(u[i]);
	}
	for (int i = 0; i < n; i++)
	{
	    col.ad(0);
	    if(a[i]) need[i] = 1;
	    else need[i] = (int)g[i].size();
	}
	for (int i = 0; i < n; i++)
	{
	    smth();
	    for (int j = 0; j < n; j++)
	    {
	        if(r[j] && !col[j]) r[j] = 0;
	    }
	}
    return col;
}

Compilation message (stderr)

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for (int i = 0; i < u.size(); i++)
      |                  ~~^~~~~~~~~~
#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...