Submission #752244

#TimeUsernameProblemLanguageResultExecution timeMemory
752244sophiadammPictionary (COCI18_pictionary)C++17
140 / 140
192 ms3296 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100005 const int INF = 0x3f3f3f3f; int p[MAXN], pp[MAXN], w[MAXN]; int n, m, q; int find(int x){ if(p[x]==x) return x; return find(p[x]); } void join(int x, int y, int t){ x=find(x); y=find(y); if(x==y) return; if(w[x] > w[y]) swap(x, y); p[x] = y; pp[x] = t; w[y] += w[x]; } void solve( int id ){ int k = m - id + 1; for( int i = 2*k; i <= n; i += k ) join(k, i, id ); } int main(){ ios_base::sync_with_stdio(false); cout.tie(NULL); cin >> n >> m >> q; for(int i = 1; i<=n; i++){ p[i] = i; pp[i] = INF; w[i] = 1; } for(int i = 1; i<=m; i++) solve(i); for(int i = 0; i<q; i++){ int a, b; cin >> a >> b; int res = 0; while(a != b){ if(pp[a] > pp[b]) swap(a, b); res = max(res, pp[a]); a = p[a]; } cout << res << endl; } }
#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...