# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
648946 | blue | Thousands Islands (IOI22_islands) | C++17 | 1093 ms | 18804 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);
vi incedge(mx, -1);
void gettime()
{
for(int j = 1; j <= 500'000; j++)
cerr << "hello world\n";
}
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(outdeg[i] == 0)
{
pushed[i] = 1;
tbv.push(i);
}
}
if(pushed[src])
{
// gettime();
return false;
}
vi originlist;
cerr << sz(tbv) << " ! \n";
cerr << "outdeg 1 = " << outdeg[1] << '\n';
while(1)
{
if(!tbv.empty())
{
int u = tbv.front();
tbv.pop();
killed[u] = 1;
for(pii vp : revedge[u])
{
int v = vp.first;
cerr << "remove out edge from " << v << " to del node = " << u << ", edge ind = " << vp.second << '\n';
outdeg[v]--;
cerr << "outdeg " << v << " = " << outdeg[v] << '\n';
if(outdeg[v] == 0)
{
pushed[v] = 1;
if(v == src)
{
gettime();
return false;
}
tbv.push(v);
cerr << "push " << v << " to killing queue\n";
}
}
}
else if(outdeg[src] == 1)
{
int newsrc;
for(pii vp : edge[src])
{
if(!pushed[vp.first])
{
newsrc = vp.first;
incedge[newsrc] = vp.second;
break;
}
}
pushed[src] = 1;
killed[src] = 1;
originlist.push_back(src);
for(pii vp : revedge[src])
{
int v = vp.first;
if(vp.second == incedge[src])
continue;
cerr << "remove out edge from " << v << " to src = " << src << ", edge ind = " << vp.second << '\n';
outdeg[v]--;
cerr << "outdeg " << v << " = " << outdeg[v] << '\n';
if(outdeg[v] == 0)
{
pushed[v] = 1;
if(pushed[newsrc])
return false;
tbv.push(v);
cerr << "push " << v << " to killing queue\n";
}
}
cerr << src << " -> " << newsrc << '\n';
src = newsrc;
}
else
{
break;
}
}
// for(int j = 1; j <= 500'000; j++)
// cerr << "hello world\n";
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... |