Submission #838042

#TimeUsernameProblemLanguageResultExecution timeMemory
838042caganyanmazConnecting Supertrees (IOI20_supertrees)C++17
21 / 100
162 ms24012 KiB
#include <bits/stdc++.h> #include "supertrees.h" using namespace std; constexpr static int MXN = 1e3 + 5; struct Node { int head, tail, size, nxt; Node(int i) : head(i), tail(i), size(1), nxt(-1) {} Node() : Node(-1) {} }; Node node[MXN]; void merge(int a, int b); int construct(vector<vector<int>> p) { int n = p.size(); vector<vector<int>> answer(n, vector<int>(n)); for (int i = 0; i < n; i++) node[i] = Node(i); for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { if (p[i][j] && node[i].head != node[j].head) { merge(node[i].head, node[j].head); answer[i][j] = answer[j][i] = 1; } } } for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) if (!p[i][j] && node[i].head == node[j].head) return 0; build(answer); return 1; } void merge(int a, int b) { if (node[a].size < node[b].size) swap(a, b); node[a].size += node[b].size; node[node[a].tail].nxt = b; node[a].tail = node[b].tail; for (;b!=-1;b=node[b].nxt) node[b].head = a; }
#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...