이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1000 + 7;
int tab[N][N], sp[N];
vector<vector<int>> answer;
int vis[N];
void L(int a, int b)
{
answer[a - 1][b - 1] = 1;
answer[b - 1][a - 1] = 1;
}
int construct(vector<vector<int>> xd)
{
int n = xd.size();
answer = xd;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
{
answer[i - 1][j - 1] = 0;
tab[i][j] = xd[i - 1][j - 1];
if(tab[i][j] == 3) return 0;
}
for(int i = 1; i <= n; ++i)
{
if(sp[i] == 0) sp[i] = i;
for(int j = i + 1; j <= n; ++j)
{
if(sp[i] == sp[j] && tab[i][j] != 1) return 0;
if(tab[i][j] != 1) continue;
if(tab[i][j] == 1 && sp[j] == 0)
{
L(i, j);
sp[j] = sp[i];
}
if(sp[i] != sp[j]) return 0;
}
}
cerr << "xd2\n";
for(int i = 1; i <= n; ++i)
{
for(int j = i + 1; j <= n; ++j)
{
if(sp[i] == sp[j] && tab[i][j] != 1) return 0;
if(sp[i] == sp[j]) continue;
if(tab[i][j] != tab[sp[i]][sp[j]]) return 0;
}
}
for(int i = 1; i <= n; ++i)
{
if(sp[i] != i) continue;
if(vis[i])
{
//cerr << "vis: " << i << " " << vis[i] << "\n";
for(int j = i + 1; j <= n; ++j)
if(tab[i][j] == 2 && vis[i] != vis[j] && sp[j] == j)
return 0;
continue;
}
//cerr << "cyc " << i << "\n";
vector<int> cur;
cur.pb(i);
for(int j = 1; j <= n; ++j)
{
if(tab[i][j] == 2 && vis[j]) return 0;
if(sp[j] == j && tab[i][j] == 2)
cur.pb(j);
}
/*cerr << "cur " << cur.size() << "\n";
for(int j = 0; j < (int)cur.size(); ++j)
cerr << cur[j] << " ";
cerr << "\n";*/
if(cur.size() == 1) continue;
for(int l = 0; l < (int)cur.size(); ++l)
for(int j = l + 1; j < (int)cur.size(); ++j)
if(tab[cur[l]][cur[j]] != 2) return 0;
for(int j = 1; j < (int)cur.size(); ++j)
{
L(cur[j - 1], cur[j]);
vis[cur[j]] = i;
}
L(cur.back(), cur[0]);
cerr << "end\n";
}
build(answer);
return 1;
}
# | 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... |