Submission #419430

#TimeUsernameProblemLanguageResultExecution timeMemory
419430vkgainzConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
279 ms22044 KiB
#include <bits/stdc++.h> using namespace std; void build(vector<vector<int>> b); int construct(vector<vector<int>> p) { int n = (int) p.size(); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(p[i][j] == 3) return 0; if(p[i][j] != p[j][i]) return 0; } } vector<vector<int>> put(n, vector<int>(n)); vector<bool> vis(n); vector<bool> inTree(n); for(int x = 0; x < n; x++) { if(vis[x]) continue; queue<int> q; vector<int> f, s; q.push(x); vis[x] = true; while(!q.empty()) { auto curr = q.front(); f.push_back(curr); q.pop(); for(int next = 0; next < n; next++) { if(p[curr][next] == 0) continue; if(p[curr][next] == 1) { if(!vis[next]) { vis[next] = true; q.push(next); } } } } for(int i = 0; i < (int) f.size(); i++) { for(int j = i + 1; j < (int) f.size(); j++) { if(p[f[i]][f[j]] != 1) return 0; } } for(int i = 0; i < (int) f.size(); i++) { for(int j = 0; j < n; j++) { if(p[f[i]][j] == 2) s.push_back(j); } } sort(s.begin(), s.end()); unique(s.begin(), s.end()); if(s.size() == 1) return 0; for(int i = 0; i < (int) s.size(); i++) { for(int j = i + 1; j < (int) s.size(); j++) { if(p[s[i]][s[j]] != 2) return 0; } } for(int i = 0; i < (int) s.size(); i++) { for(int j = 0; j < (int) f.size(); j++) { if(p[s[i]][f[j]] != 2) return 0; } } for(int i = 0; i < (int) f.size() - 1; i++) { put[f[i]][f[i + 1]] = 1, put[f[i + 1]][f[i]] = 1; } if(s.empty()) continue; for(int i = 0; i < (int) s.size() - 1; i++) { put[s[i]][s[i + 1]] = 1, put[s[i + 1]][s[i]] = 1; } put[x][s[0]] = 1, put[s[0]][x] = 1; put[x][s.back()] = 1, put[s.back()][x] = 1; } build(put); 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...