Submission #583544

#TimeUsernameProblemLanguageResultExecution timeMemory
583544Markomafko972KOVANICE (COI15_kovanice)C++14
100 / 100
232 ms30524 KiB
#include <bits/stdc++.h> using namespace std; int n, m, q; int a[300005]; int b[300005]; char w[300005]; int prt[300005]; vector<int> v[300005]; int dub[300005]; int sol[300005]; int find(int x) { if (prt[x] == x) return x; return prt[x] = find(prt[x]); } void unija(int x, int y) { x = find(x); y = find(y); if (x == y) return; prt[y] = x; } int dfs(int x) { if (dub[x] > 0) return dub[x]; for (int i = 0; i < v[x].size(); i++) { dub[x] = max(dub[x], dfs(v[x][i])); } dub[x]++; return dub[x]; } void rek(int x) { sol[x] = dub[x]; for (int i = 0; i < v[x].size(); i++) { if (sol[v[x][i]] == 0 && dub[v[x][i]]+1 == dub[x]) rek(v[x][i]); } } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> q; for (int i = 1; i <= m; i++) prt[i] = i; for (int i = 0; i < q; i++) { cin >> a[i] >> w[i] >> b[i]; if (w[i] == '=') unija(a[i], b[i]); } for (int i = 0; i < q; i++) { int poc = find(a[i]), kr = find(b[i]); if (w[i] == '>') v[poc].push_back(kr); else if (w[i] == '<') v[kr].push_back(poc); } for (int i = 1; i <= m; i++) { if (dub[find(i)] == 0) dfs(find(i)); } for (int i = 1; i <= m; i++) { if (sol[find(i)] == 0 && dub[find(i)] == n) rek(find(i)); } for (int i = 1; i <= m; i++) { if (sol[find(i)] == 0) cout << "?\n"; else cout << "K" << sol[find(i)] << "\n"; } return 0; }

Compilation message (stderr)

kovanice.cpp: In function 'int dfs(int)':
kovanice.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for (int i = 0; i < v[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
kovanice.cpp: In function 'void rek(int)':
kovanice.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for (int i = 0; i < v[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...