Submission #1120579

#TimeUsernameProblemLanguageResultExecution timeMemory
1120579vjudge1KOVANICE (COI15_kovanice)C++17
100 / 100
320 ms54748 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long long struct DSU{ vector<int> p; DSU(int n){ p.assign(n + 1, -1); } int find(int x){ if (p[x] < 0) return x; return p[x] = find(p[x]); } void merge(int u, int v){ u = find(u); v = find(v); if (u == v) return; if (p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; } }; vector<vector<int>> v, vr; vector<int> ord, vis, lb, rb; void dfs(int x){ vis[x] = 1; for (auto el : v[x]){ if (vis[el] == 0){ dfs(el); } } ord.push_back(x); } int main(){ string inp; int n, m, c, a, b; cin>>n>>m>>c; v.assign(m + 1, vector<int>()), vr.assign(m + 1, vector<int>()), vis.assign(m + 1, 0), lb.assign(m + 1, 1), rb.assign(m + 1, n); vector<vector<int>> edg; DSU ds(m + 1); for (int i = 0; i < c; i++){ string s1 = "", s2 = ""; cin>>inp; int f = 0; for (int i = 0; i < inp.size(); i++){ if (inp[i] == '='){ f = 2; } else if (inp[i] == '<'){ f = 1; } else if (inp[i] == '>'){ f = 3; } else{ if (f == 0){ s1 += inp[i]; } else{ s2 += inp[i]; } } } a = stoi(s1), b = stoi(s2); if (f == 1){ edg.push_back({a, b}); } else if (f == 2){ ds.merge(a, b); } else{ edg.push_back({b, a}); } } for (int i = 0; i < edg.size(); i++){ a = ds.find(edg[i][0]), b = ds.find(edg[i][1]); v[a].push_back(b); vr[b].push_back(a); } for (int i = 1; i <= m; i++){ if (vis[i] == 0){ dfs(i); } } reverse(ord.begin(), ord.end()); for (auto i : ord){ for (auto el : vr[i]){ lb[i] = max(lb[i], lb[el] + 1); } } reverse(ord.begin(), ord.end()); for (auto i : ord){ for (auto el : v[i]){ rb[i] = min(rb[i], rb[el] - 1); } } for (int i = 1; i <= m; i++){ int a = ds.find(i); if (lb[a] == rb[a]){ cout<<"K"<<lb[a]<<"\n"; } else{ cout<<"?\n"; } } }

Compilation message (stderr)

kovanice.cpp: In function 'int main()':
kovanice.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for (int i = 0; i < inp.size(); i++){
      |                         ~~^~~~~~~~~~~~
kovanice.cpp:75:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for (int i = 0; i < edg.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...