Submission #240274

#TimeUsernameProblemLanguageResultExecution timeMemory
240274MrRobot_28Planinarenje (COCI18_planinarenje)C++17
160 / 160
219 ms1148 KiB
#include<bits/stdc++.h> using namespace std; vector <vector <int> > g; vector <int> used, mat, mat1; bool dfs(int v, int cnt) { if(used[v] == cnt) { return false; } used[v] = cnt; for(int i = 0; i < g[v].size(); i++){ int to = g[v][i]; if(mat[to] == -1 || dfs(mat[to], cnt)) { mat[to] = v; return true; } } return false; } bool dfs1(int v, int cnt) { if(used[v] == cnt) { return false; } used[v] = cnt; for(int i = 0; i < g[v].size(); i++){ int to = g[v][i]; if(used[to] == cnt) { continue; } if(mat1[to] == -1 || dfs1(mat1[to], cnt)) { mat1[to] = v; return true; } } return false; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; g.resize(2 * n); mat1.resize(2 * n ,-1); mat.resize(2 * n, -1); used.resize(2 * n); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; b += n; g[a].push_back(b); g[b].push_back(a); } for(int i = 0;i < n; i++) { dfs(i, i + 1); } int cnt1 = 0; for(int i = n; i < n * 2; i++) { if(mat[i] != -1) { cnt1++; } } vector <bool> ans(n); for(int i = 0; i < n; i++) { int st = -1; for(int j = 0; j < 2 * n; j++){ mat1[j] = -1; } for(int j = 0; j < 2 * n; j++) { if(mat[j] != -1 && mat[j] != i) { mat1[mat[j]] = j; } if(mat[j] == i) { st = j; } } used[i] = n + i + 1; if(st != -1) { dfs1(st, n + i + 1); } int cnt2 = 0; for(int j = 0; j < n; j++) { if(mat1[j] != -1) { cnt2++; } } if(cnt1 == cnt2) { ans[i] = true; } else { ans[i] = false; } } for(int i = 0; i < n; i++) { if(ans[i]) { cout << "Mirko\n"; } else { cout << "Slavko\n"; } } return 0; }

Compilation message (stderr)

planinarenje.cpp: In function 'bool dfs(int, int)':
planinarenje.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[v].size(); i++){
                 ~~^~~~~~~~~~~~~
planinarenje.cpp: In function 'bool dfs1(int, int)':
planinarenje.cpp:29:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < g[v].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...
#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...