Submission #295878

#TimeUsernameProblemLanguageResultExecution timeMemory
295878shrek12357KOVANICE (COI15_kovanice)C++14
20 / 100
29 ms3352 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <set> #include <climits> #include <cmath> #include <fstream> #include <queue> using namespace std; #define MAXN 1005 vector<int> eq[MAXN]; vector<pair<int, int>> rest; int n, m, k; vector<int> adjList[MAXN]; int counts[MAXN]; bool checked[MAXN]; int compress[MAXN]; int ans[MAXN]; void fill(int src, int val) { compress[src] = val; for (auto i : eq[src]) { if (compress[i] == -1) { fill(i, val); } } } int d[MAXN], r[MAXN]; vector<int> gd[MAXN], gr[MAXN]; int dfsx(int v) { if (d[v]) return d[v]; for (int i : gd[v]) d[v] = max(d[v], dfsx(i)); return ++d[v]; } int dfsy(int v) { if (r[v]) return r[v]; for (int i : gr[v]) r[v] = max(r[v], dfsy(i)); return ++r[v]; } void dfs(int src, int depth) { checked[src] = true; for (auto i : adjList[src]) { if (!checked[i]) { dfs(i, depth + 1); } } if (depth == n) { ans[src] = 1; return; } for (auto i : adjList[src]) { if (ans[i] != -1) { ans[src] = ans[i] + 1; return; } } } int main() { cin.tie(); ios_base::sync_with_stdio(0); cin >> n >> m >> k; for (int i = 0; i <= m; i++) { counts[i] = 0; compress[i] = -1; ans[i] = -1; checked[i] = false; } for (int i = 0; i < k; i++) { int node1, node2; char mark; cin >> node1 >> mark >> node2; if (mark == '=') { eq[node1].push_back(node2); eq[node2].push_back(node1); continue; } rest.push_back({ node1, node2 }); } for (int i = 1; i <= m; i++) { if (compress[i] == -1) { fill(i, i); } } for (int i = 0; i < rest.size(); i++) { gd[compress[rest[i].first]].push_back(compress[rest[i].second]); gr[compress[rest[i].second]].push_back(compress[rest[i].first]); counts[compress[rest[i].second]]++; } for (int i = 1; i <= m; i++) { dfsx(compress[i]); dfsy(compress[i]); } for (int i = 1; i <= m; i++) { if (d[compress[i]] + r[compress[i]] == n + 1)cout << "K" << r[compress[i]] << endl; else cout << "?" << endl; } /* for (int i = 1; i <= m; i++) { if (ans[compress[i]] != -1) { cout << "K"; cout << ans[compress[i]] << endl; } else { cout << "?" << endl; } }*/ }

Compilation message (stderr)

kovanice.cpp: In function 'int main()':
kovanice.cpp:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |  for (int i = 0; i < rest.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...