Submission #873349

#TimeUsernameProblemLanguageResultExecution timeMemory
873349teokakabadzeConnecting Supertrees (IOI20_supertrees)C++17
65 / 100
189 ms28240 KiB
#include "supertrees.h" #include<bits/stdc++.h> #define pb push_back using namespace std; int a[1005][1005], i, j, f[1005], a2, a3, k, l, cnt, c, pr[1005]; vector<int> s, d, e; int construct(std::vector<std::vector<int>> p) { int n = p.size(); std::vector<std::vector<int>> answer; for(i = 0; i < n; i++) for(j = 0; j < n; j++) { if(p[i][j] == 3) return 0; if(p[i][j] != p[j][i]) return 0; } for(i = 0; i < n; i++) { a2 = 0; for(j = 0; j < n; j++) if(p[i][j] == 2) a2 = 1; if(!f[i]) { e.clear(); d.clear(); if(a2) k = 2; else k = 1; f[i] = 1, l = i, cnt = 0; if(k == 2) for(int b = 0; b < n; b++) { if(!f[b] && p[i][b] == 1) { f[b] = 1, a[i][b] = a[b][i] = 1; if(k == 2) e.pb(b); else d.pb(b); pr[b] = i; } if(f[b] == 2 && p[i][b]) return 0; } d.pb(i); for(j = 0; j < n; j++) if(!f[j] && p[l][j] == k) { f[j] = 1; d.pb(j); a[l][j] = a[j][l] = 1; for(int b = 0; b < n; b++) { if(!f[b] && p[j][b] == 1) { f[b] = 1, a[j][b] = a[b][j] = 1; if(k == 2) e.pb(b); else d.pb(b); pr[b] = j; } if(f[b] == 2 && p[j][b]) return 0; } l = j; cnt++; } else if(f[j] == 2 && p[i][j]) return 0; if(k == 2 && cnt < 2) return 0; if(k == 2) a[l][i] = a[i][l] = 1; for(j = 0; j < n; j++) if(f[j] == 1) f[j] = 2; for(auto x : d) for(auto y : e) if(!a[x][y] && p[x][y] != k) return 0; for(auto x : d) for(auto y : d) if(x != y && p[x][y] != k) return 0; for(auto x : e) for(auto y : e) { if(x != y && pr[x] != pr[y] && p[x][y] != k) return 0; if(x != y && pr[x] == pr[y] && p[x][y] != 1) return 0; } } } for(i = 0; i < n; i++) { for(j = 0; j < n; j++) s.push_back(a[i][j]); answer.push_back(s); s.clear(); } build(answer); return 1; }
#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...