Submission #312014

#TimeUsernameProblemLanguageResultExecution timeMemory
312014BlerarghConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
1093 ms30076 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; #define FOR(i,a,b) for (int i=(a); i<=(b); i++) #define ROF(i,a,b) for (int i=(a); i>=(b); i--) #define gay cout << "gay"; bool visited[1005]; int parent[1005], n; vector<vector<int> > answer, pp; int fp(int a){ if (a == parent[a]) return a; else return parent[a] = fp(parent[a]); } bool join(int a, int b){ int pa = fp(a); int pb = fp(b); if (pa!=pb) { parent[b] = a; return 1; } else return 0; } void dfs(int u, int start){ visited[fp(u)] = 1; bool check=0; FOR(i,0,n-1){ if (pp[u][i] != 2) continue; else if (!visited[fp(i)]) { answer[u][i] = answer[i][u] = 1; dfs(i, start); check = 1; } } if (!check && start!=u) answer[u][start] = answer[start][u] = 1; return; } vector<vector<int> > chk; bool visiting[1005]; void dfscheck(int u, int start){ //cout << u << '\n'; visiting[u] = 1; chk[start][u]++; FOR(i,0,n-1){ if (!answer[u][i]) continue; if (!visiting[i]) dfscheck(i, start); } visiting[u] = 0; return; } bool test(){ FOR(i,0,n-1){ visiting[i] = 0; vector<int> row; row.resize(n); chk.push_back(row); } FOR(i,0,n-1){ dfscheck(i,i); } /* FOR(i,0,n-1){ FOR(j,0,n-1){ cout << chk[i][j] << " "; } cout << '\n'; } */ if (chk == pp) return 1; else return 0; } int construct(vector<vector<int> > p){ pp = p; n = p.size(); FOR(i,0,n-1){ parent[i] = i; } answer.clear(); FOR(i,0,n-1){ vector<int> row; row.resize(n); answer.push_back(row); } bool imposs=0; FOR(i,0,n-1) { FOR(j,0,n-1){ if (i==j && p[i][j] != 1) imposs=1; if (p[i][j] != p[j][i]) imposs=1; if (p[i][j] == 3) imposs=1; if (imposs) break; if (p[i][j] == 1 && join(i,j)) answer[i][j] = answer[j][i] = 1; } if (imposs) break; } if (imposs) return 0; FOR(i,0,n-1){ if (!visited[fp(i)]) dfs(i,i); } if (test()) { build(answer); return 1; } else return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...