# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46452 | alex99 | Pipes (CEOI15_pipes) | C++14 | 4106 ms | 7516 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 <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
int N, M;
int TT[100005], R[100005];
long long Sum[100005];
vector <int> G[100005];
bool Use[100005];
void Unite(int x, int y)
{
if(x == y)
return;
if(R[x] < R[y])
{
TT[x] = y;
}
else
TT[y] = x;
if(R[x] == R[y])
R[x]++;
}
int Father(int x)
{
int init = x;
while(x != TT[x])
x = TT[x];
while(init != x)
{
int next = TT[init];
TT[init] = x;
init = next;
}
return x;
}
void DFS(int node, int father)
{
Use[node] = 1;
for(int i = 0; i < G[node].size(); i++)
{
int neighb = G[node][i];
if(neighb == father)
continue;
DFS(neighb, node);
Sum[node] += Sum[neighb];
}
if(Sum[node] == 0 && father != 0)
{
cout << node << " " << father << "\n";
}
}
void Solve()
{
cin >> N >> M;
for(int i = 1; i <= N; i++)
TT[i] = i;
for(int i = 1; i <= M; i++)
{
int x, y;
cin >> x >> y;
if(Father(x) == Father(y))
{
int r = rand();
Sum[x] += r;
Sum[y] -= r;
}
else
{
G[x].push_back(y);
G[y].push_back(x);
Unite(Father(x), Father(y));
}
}
for(int i = 1; i <= N; i++)
if(Use[i] == 0)
DFS(i, 0);
}
int main()
{
srand(time(NULL));
Solve();
return 0;
}
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... |
# | 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... |