Submission #227726

#TimeUsernameProblemLanguageResultExecution timeMemory
227726AaronNaiduToy Train (IOI17_train)C++14
0 / 100
69 ms1688 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> a, r, f;
vector<int> graph[6000];
vector<bool> visited;
int givesAWin[6000];
pair<bool, int> inCycle[6000];
vector<int> DFSpath;
vector<int> goodsInPath;

bool cycleTime(int node, int orig) {
    if (r[node])
    {
        return true;
    }
    if (node == orig)
    {
        return false;
    }
    return cycleTime(f[node], orig);
}

void checkForCycle(int node, int starter, bool atStart) {
   // cout << "Checking " << node << "\n";
    if (inCycle[node].first and inCycle[node].second <= goodsInPath[goodsInPath.size() - 1])
    {
        //cout << "In the cycle\n";
        for (int i = 0; i < DFSpath.size(); i++)
        {
            //cout << DFSpath[i] << " gives a win\n";
            givesAWin[DFSpath[i]] = true;
        }
        //cout << "Leaving " << node << "\n";
        return;
    }
    
    if (visited[node])
    {
        //cout << "Already visited\n";
        if (givesAWin[node])
        {
           // cout << "Known to give a win\n";
           for (auto i : DFSpath)
            {
               // cout << DFSpath[i] << " gives a win\n";
                givesAWin[i] = true;
            }
        }
      //  cout << "Leaving " << node << "\n";
        return;
    }
    inCycle[node] = {true, DFSpath.size()};
    if (r[node])
    {
       // cout << node << " is a charging station\n";
        goodsInPath.push_back(DFSpath.size());
    }
    visited[node] = true;
    DFSpath.push_back(node);
    for (auto i : graph[node])
    {
        checkForCycle(i, starter, atStart);
    }
    inCycle[node].first = false;
    DFSpath.pop_back();
    if (r[node])
    {
        goodsInPath.pop_back();
    }
   // cout << "Leaving " << node << "\n";
}

vector<int> who_wins(vector<int> la, vector<int> lr, vector<int> lu, vector<int> lv) {
    a = la;
    r = lr;
    for (int i = 0; i < lu.size(); i++)
    {
        graph[lu[i]].push_back(lv[i]);
    }
    for (int i = 0; i < a.size(); i++)
    {
        f.push_back(-1);
        visited.push_back(false);
    }
    for (int i = 0; i < r.size(); i++)
    {
        if (!visited[i])
        {          
            checkForCycle(i, i, true);
        }
    }
    vector<int> toRet;
    for (int i = 0; i < a.size(); i++)
    {
        toRet.push_back(givesAWin[i]);
    }
    return toRet;
}

Compilation message (stderr)

train.cpp: In function 'void checkForCycle(int, int, bool)':
train.cpp:29:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < DFSpath.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:77:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < lu.size(); i++)
                     ~~^~~~~~~~~~~
train.cpp:81:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i++)
                     ~~^~~~~~~~~~
train.cpp:86:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < r.size(); i++)
                     ~~^~~~~~~~~~
train.cpp:94:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.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...