Submission #419415

#TimeUsernameProblemLanguageResultExecution timeMemory
419415vkgainzConnecting Supertrees (IOI20_supertrees)C++17
11 / 100
235 ms23888 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(); vector<int> mx(n); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(p[i][j] == 3) return 0; mx[i] = max(mx[i], p[i][j]); } } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(p[i][j] == 1 && mx[j] > 1) return 0; } } vector<vector<int>> put(n, vector<int>(n)); vector<bool> vis(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] == 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() - 1; i++) { put[f[i]][f[i + 1]] = 1, put[f[i + 1]][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...