# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398420 | iulia13 | Connecting Supertrees (IOI20_supertrees) | C++14 | 1085 ms | 30248 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 "supertrees.h"
using namespace std;
#define pb push_back
const int nmax = 1005;
vector <int> comp;
vector <int> comp2;
vector <int> ciclu;
vector <int> g[nmax];
vector <int> G[nmax];
int viz[nmax], viz2[nmax], viz3[nmax];
void dfs(int nod)
{
comp.pb(nod);
viz[nod] = 1;
for (auto x : g[nod])
if (!viz[x])
dfs(x);
}
void dfs2(int nod)
{
comp2.pb(nod);
viz2[nod] = 1;
for (auto x : G[nod])
if (!viz2[x])
dfs2(x);
}/*
void build(vector < vector <int> > ans)
{
int n = ans.size();
for (int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
cout << ans[i][j] << " ";
cout << endl;
}
}*/
int construct (vector < vector <int> > p)
{
int n = p.size();
vector<vector<int>> ans;
ans.resize(n);
int i, j;
for (i = 0; i < n; i++)
{
ans[i].resize(n);
for (j = i + 1; j < n; j++)
{
if (p[i][j] == 3)
return 0;
if (p[i][j])
{
g[i].pb(j);
g[j].pb(i);
}
}
}
for (int iii = 0; iii < n; iii++)
{
if (viz[iii])
continue;
ciclu.clear();
comp.clear();
dfs(iii);
int x = comp.size();
for (i = 0; i < x; i++)
for (j = 1 + i; j < x; j++)
{
int ii = comp[i];
int jj = comp[j];
if (!p[ii][jj])
return 0;
if (p[ii][jj] == 1)
{
G[ii].pb(jj);
G[jj].pb(ii);
}
}
for (int ii = 0; ii < x; ii++)
{
i = comp[ii];
if (viz2[i])
continue;
comp2.clear();
dfs2(i);
int x2 = comp2.size();
for (auto nod : comp2)
viz3[nod] = 1;
for (auto a : comp)
for (auto b : comp)
{
if (viz3[a] && viz3[b] && p[a][b] != 1)
return 0;
if (viz3[a] && !viz3[b] && p[a][b] != 2)
return 0;
if (!viz3[a] && viz3[b] && p[a][b] != 2)
return 0;
}
for (auto nod : comp2)
viz3[nod] = 0;
for (i = 0; i < x2 - 1; i++)
{
int a = comp[i];
int b = comp[i + 1];
ans[a][b] = 1;
ans[b][a] = 1;
}
ciclu.pb(comp2[0]);
}
int x2 = ciclu.size();
if (x2 == 2)
return 0;
if (x2 < 2)
continue;
for (i = 0; i < x2 - 1; i++)
{
ans[ciclu[i]][ciclu[i + 1]] = 1;
ans[ciclu[i + 1]][ciclu[i]] = 1;
}
x2--;
ans[ciclu[0]][ciclu[x2]] = 1;
ans[ciclu[x2]][ciclu[0]] = 1;
}
build(ans);
return 1;
}/*
int main()
{
int n, i, j;
cin >> n;
vector <vector <int>> p;
p.resize(n);
for (i = 0; i < n; i++)
p[i].resize(n);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
cin >> p[i][j];
construct(p);
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... |