Submission #754605

#TimeUsernameProblemLanguageResultExecution timeMemory
754605MilosMilutinovicPictionary (COCI18_pictionary)C++14
140 / 140
95 ms12548 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; vector<pair<int, int>> qs[N]; int n, m, q, fa[N], ans[N]; int gfa(int x) { return fa[x] == x ? x : fa[x] = gfa(fa[x]); } void unite(int x, int y, int w) { x = gfa(x); y = gfa(y); if (x == y) { return; } if (qs[x].size() < qs[y].size()) { swap(x, y); } for (auto& p : qs[y]) { if (gfa(p.first) == x) { ans[p.second] = w; } else { qs[x].push_back(p); } } fa[y] = x; } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= n; i++) { fa[i] = i; } for (int i = 1; i <= q; i++) { int a, b; scanf("%d%d", &a, &b); qs[a].emplace_back(b, i); qs[b].emplace_back(a, i); } for (int d = m; d >= 1; d--) { vector<int> vec; for (int i = d; i <= n; i += d) { vec.push_back(i); } for (int i = 0; i + 1 < vec.size(); i++) { unite(vec[i], vec[i + 1], m - d + 1); } } for (int i = 1; i <= q; i++) { printf("%d\n", ans[i]); } return 0; }

Compilation message (stderr)

pictionary.cpp: In function 'int main()':
pictionary.cpp:41:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int i = 0; i + 1 < vec.size(); i++) {
      |                         ~~~~~~^~~~~~~~~~~~
pictionary.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d%d%d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
pictionary.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
#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...