#include <iostream>
#include <cstdio>
#include <vector>
#include "train.h"
using namespace std;
const int MAX_NOEUDS = (5000);
vector <int> Remonte[MAX_NOEUDS];
bool DP[MAX_NOEUDS];
bool Arezou[MAX_NOEUDS];
bool Charge[MAX_NOEUDS];
bool Calc[MAX_NOEUDS];
bool Pris[MAX_NOEUDS];
int Deg[MAX_NOEUDS];
int File[MAX_NOEUDS];
int deb = 0, fin = 0;
int nbNoeuds, nbAretes;
void Reset() {
deb = 0, fin = 0;
for (int i = 0; i < nbNoeuds; i ++)
{
Calc[i] = false;
Pris[i] = false;
Deg[i] = 0;
}
for (int i = 0; i < nbNoeuds; i ++)
{
for (int dest : Remonte[i])
Deg[dest] ++;
}
return;
}
void Add(int noeud) {
if (Calc[noeud])
return;
Calc[noeud] = true;
for (int dest : Remonte[noeud])
{
if (!Pris[dest] && (Arezou[dest] || -- Deg[dest] == 0))
{
File[fin ++] = dest;
Pris[dest] = true;
}
}
return;
}
bool Bfs() {
for (int i = 0; i < nbNoeuds; i ++)
{
if (DP[i] && Charge[i])
Add(i);
}
while (deb < fin)
{
Add(File[deb ++]);
}
bool isOver = true;
for (int i = 0; i < nbNoeuds; i ++)
{
if (DP[i] && !Pris[i])
{
DP[i] = false;
isOver = false;
}
}
return isOver;
}
vector<int> who_wins(vector<int> Proprio, vector<int> Energie, vector<int> Left, vector<int> Right) {
nbNoeuds = Proprio.size();
nbAretes = Left.size();
for (int i = 0; i < nbNoeuds; i ++)
{
Arezou[i] = Proprio[i];
Charge[i] = Energie[i];
if (Charge[i])
DP[i] = true;
}
for (int i = 0; i < nbAretes; i ++)
{
Remonte[Right[i]].push_back(Left[i]);
}
Reset();
while (!Bfs())
Reset();
vector <int> Ans;
for (int i = 0; i < nbNoeuds; i ++)
{
Ans.push_back(DP[i]);
}
return Ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
844 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
3rd lines differ - on the 4th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
1080 KB |
Output is correct |
2 |
Correct |
204 ms |
1080 KB |
Output is correct |
3 |
Correct |
282 ms |
1068 KB |
Output is correct |
4 |
Incorrect |
14 ms |
1324 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1172 KB |
3rd lines differ - on the 21st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
1308 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
844 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |