Submission #825321

#TimeUsernameProblemLanguageResultExecution timeMemory
825321HorizonWestConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
1 ms232 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define db double #define ll __int128 //#define int long long #define pb push_back #define fs first #define sd second #define Mod long(1e9 + 7) #define all(x) x.begin(), x.end() #define unvisited long(-1) #define Eps double(1e-9) #define _for(i, n) for(int i = 0; i < (n); i++) #define dbg(x) cout << #x ": " << x << endl; const int Max = 1e6 + 7, Inf = 1e9 + 7; void build(std::vector<std::vector<int>> b); struct DSU { vector <int> link, size; int find(int x) { while(x != link[x]) x = link[x]; return x; } int sz(int x) { return size[find(x)]; } bool same(int a, int b) { return find(a) == find(b); } void unite(int a, int b) { a = find(a); b = find(b); if(a == b) return; if(size[a] < size[b]) swap(a, b); link[b] = a; size[a] += size[b]; } DSU(int n) { link.assign(n+1, 0); size.assign(n+1, 1); for(int i = 0; i <= n; i++) link[i] = i; } }; int construct(std::vector<std::vector<int>> p) { int n = p.size(); DSU St(n); vector <vector<int>> g, ans(n, vector <int> (n, 0)); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) if(j != i) { if(p[i][j] != p[j][i]) return 0; if(p[i][j] == 1) St.unite(i, j); } ans[i][i] = 1; } map <int, int> mp, pass; int idx = 0; for(int i = 0; i < n; i++) { int x = St.find(i); if(mp[x] == 0) { idx++; mp[x] = idx; g.push_back(vector <int> ()); } g[mp[x]-1].push_back(i); } /*for(int i = 0; i < (int) g.size(); i++) { for(int j = 0; j < g[i].size(); j++) { for(int k = j+1; k < g[i].size(); k++) { if(p[g[i][j]][g[i][k]] != 1) return 0; } pass[g[i][j]] = i+1; } for(int j = 0; j < g[i].size() - 1; j++) { ans[g[i][j]][g[i][j+1]] = 1; ans[g[i][j+1]][g[i][j]] = 1; } int x = g[i][0]; vector <int> s; for(int j = 0; j < n; j++) { if(p[x][j] == 2) { if(pass[j] != 0) return 0; pass[j] = i+1; s.push_back(j); St.unite(x, j); } } if(s.size() > 0 && s.size() < 3) return 0; if(s.size() > 0) { ans[x][s[0]] = 1; ans[s[0]][x] = 1; int mod = s.size(); for(int j = 0; j < (int) s.size(); j++) { ans[s[j]][s[(j+1) % mod]] = 1; ans[s[(j+1) % mod]][s[j]] = 1; } for(int j = 0; j < g[i].size(); j++) { for(int k = 0; k < n; k++) if(p[g[i][j]][k] != 0) { if(pass[k] != i + 1) return 0; } } for(int j = 0; j < s.size(); j++) { for(int k = 0; k < n; k++) if(p[s[j]][k] != 0) { if(pass[k] != i + 1) return 0; } } } }*/ for(int i = 0; i < n; i++) if(St.sz(i) == 1) { vector <int> s; s.push_back(i); map <int, int> mk; mk[i] = 1; for(int j = 0; j < n; j++) if(p[i][j] == 2) { mk[j] = i + 1; s.push_back(j); St.unite(i, j); } int m = (int) s.size(); for(int j = 0; j < m; j++) { for(int k = 0; k < n; k++) { if(!((p[s[j]][k] != 0) ^ (mk[k]))) return 0; } } if(m == 2) return 0; for(int j = 0; j < m; j++) { ans[s[j]][s[(j+1) % m]] = 1; ans[s[(j+1) % m]][s[j]] = 1; } } build(ans); 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...