Submission #752755

#TimeUsernameProblemLanguageResultExecution timeMemory
752755ThegeekKnight16Pictionary (COCI18_pictionary)C++17
140 / 140
57 ms1996 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; vector<int> pai, sub, edge; int find(int v) {return ((pai[v] == v) ? v : find(pai[v]));} void une(int a, int b, int temp) { a = find(a); b = find(b); if (a == b) return; if (sub[a] < sub[b]) swap(a, b); pai[b] = a; sub[a] += sub[b]; edge[b] = temp; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, M, Q; cin >> N >> M >> Q; pai.resize(N+1); edge.resize(N+1); sub.resize(N+1); iota(pai.begin(), pai.end(), 0); fill(sub.begin(), sub.end(), 1); fill(edge.begin(), edge.end(), INF); for (int i = M; i >= 1; i--) { for (int k = 2; k*i <= N; k++) une(i, k*i, M - i + 1); } // for (int i = 1; i <= N; i++) cerr << "||" << i << " " << pai[i] << " " << edge[i] << '\n'; while (Q--) { int X, Y; cin >> X >> Y; int dist = -1; while (X != Y) { if (sub[X] > sub[Y]) {dist = max(dist, edge[Y]); Y = pai[Y];} else {dist = max(dist, edge[X]); X = pai[X];} } cout << dist << '\n'; } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...