Submission #419438

#TimeUsernameProblemLanguageResultExecution timeMemory
419438vkgainzConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
289 ms22140 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<int> id(n); vector<vector<int>> store(n); for(int x = 0; x < n; x++) { if(vis[x]) continue; queue<int> q; vector<int> f; 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() - 1; i++) { put[f[i]][f[i + 1]] = 1, put[f[i + 1]][f[i]] = 1; } store[x] = f; for(int i = 0; i < (int) f.size(); i++) { id[f[i]] = x; } } vis.clear(), vis.resize(n, 0); for(int i = 0; i < n; i++) { bool zer = false, two = false; for(int j = 0; j < n; j++) { for(int x : store[i]) { for(int y : store[j]) { if(p[x][y] == 0) zer = true; if(p[x][y] == 2) two = true; } } } if(zer && two) return 0; } for(int i = 0; i < n; i++) { if(vis[i]) continue; vector<int> in; in.push_back(i); vis[i] = true; for(int j = 0; j < n; j++) { if(store[j].empty()) continue; if(p[i][j] == 2) { in.push_back(j); vis[j] = true; } } if(in.size() == 2) return 0; if(in.size() == 1) continue; for(int j = 0; j < (int) in.size(); j++) { put[in[j]][in[(j + 1) % in.size()]] = 1, put[in[(j + 1) % in.size()]][in[j]] = 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...