# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
648938 | blue | Thousands Islands (IOI22_islands) | C++17 | 45 ms | 15760 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pii>;
#define sz(x) int(x.size())
const int mx = 100'000;
vpii edge[mx];
vpii revedge[mx];
int N, M;
queue<int> tbv;
int src = 0;
vi pushed(mx, 0);
vi killed(mx, 0);
vi outdeg(mx, 0);
variant<bool, vi> find_journey(int N_, int M_, vi U, vi V)
{
N = N_;
M = M_;
for(int j = 0; j < M; j++)
{
edge[U[j]].push_back({V[j], j});
revedge[V[j]].push_back({U[j], j});
outdeg[U[j]]++;
}
for(int i = 0; i < N; i++)
{
if(sz(edge[i]) == 0)
{
pushed[i] = 1;
tbv.push(i);
}
}
if(pushed[src])
return false;
vi originlist;
// cerr << sz(tbv) << " ! \n";
while(1)
{
if(!tbv.empty())
{
int u = tbv.front();
tbv.pop();
killed[u] = 1;
for(pii vp : revedge[u])
{
int v = vp.first;
outdeg[v]--;
if(outdeg[v] == 0)
{
pushed[v] = 1;
if(pushed[src])
return false;
tbv.push(v);
}
}
}
else if(outdeg[src] == 1)
{
int newsrc;
for(pii vp : edge[src])
{
if(!killed[vp.first])
{
newsrc = vp.first;
break;
}
}
pushed[src] = 1;
killed[src] = 1;
originlist.push_back(src);
for(pii vp : revedge[src])
{
int v = vp.first;
outdeg[v]--;
if(outdeg[v] == 0)
{
pushed[v] = 1;
if(pushed[newsrc])
return false;
tbv.push(v);
}
}
src = newsrc;
}
else
{
break;
}
}
return true;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |