Submission #419424

#TimeUsernameProblemLanguageResultExecution timeMemory
419424vkgainzConnecting Supertrees (IOI20_supertrees)C++17
0 / 100
236 ms22024 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 i = 0; i < n; i++) { if(vis[i]) continue; queue<int> q; vector<int> f, s; q.push(i); vis[i] = 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); } } else { if(!vis[next]) { vis[next] = true; s.push_back(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]] != 0 || p[f[j]][f[i]] != 0) 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; inTree[f[i]] = 1; } if(s.empty()) continue; if((int) s.size() == 1) return 0; 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[i][s[0]] = 1, put[s[0]][i] = 1; put[i][s.back()] = 1, put[s.back()][i] = 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...