Submission #752750

#TimeUsernameProblemLanguageResultExecution timeMemory
752750mariaclaraPictionary (COCI18_pictionary)C++17
140 / 140
245 ms3308 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 1e5+10; typedef pair<int,int> pii; #define mk make_pair #define pb push_back #define f first #define s second int n, m, q, day, t[MAXN], pai[MAXN], sz[MAXN], comp; int find(int x) { if(pai[x]==x) return x; return find(pai[x]); } void merge(int x, int y, int Time) { x = find(x); y = find(y); if(x==y) return; if(sz[x]>sz[y]) swap(x,y); pai[x] = y; t[x] = Time; sz[y] += sz[x]; } int main() { cin >> n >> m >> q; for(int i = 1; i <= n; i++) pai[i] = i, sz[i] = 1, t[i] = 1e9; while(m--) { day++; for(int i = 2*m+2; i <= n; i+=m+1) merge(m+1, i, day); } while(q--) { int a, b, resp = 0; cin >> a >> b; while(a!=b) { if(t[a]<t[b]) resp = t[a], a = pai[a]; else resp = t[b], b = pai[b]; } cout << resp <<"\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...