Submission #1013707

#TimeUsernameProblemLanguageResultExecution timeMemory
1013707ThegeekKnight16Simurgh (IOI17_simurgh)C++17
51 / 100
59 ms2632 KiB
#include <bits/stdc++.h> #include "simurgh.h" using namespace std; vector<int> pai, sub; int find(int v) {return pai[v] = (pai[v] == v ? v : find(pai[v]));} void une(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (sub[x] < sub[y]) swap(x, y); pai[y] = x; sub[x] += sub[y]; } std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) { int M = u.size(); vector<int> Marc(M); vector<int> good; for (int i = 0; i < M && good.size() < n-1; i++) { if (Marc[i]) continue; int U = u[i], V = v[i]; pai.resize(n); sub.resize(n); iota(pai.begin(), pai.end(), 0); fill(sub.begin(), sub.end(), 1); vector<int> r; vector<int> poss; for (auto j : good) une(u[j], v[j]), r.push_back(j); if (find(U) == find(V)) continue; for (int j = 0; j < M; j++) { if (Marc[j]) continue; int X = u[j], Y = v[j]; if (find(X) == find(Y)) continue; if ((find(X) == find(U) && find(Y) == find(V)) || (find(X) == find(V) && find(Y) == find(U))) { poss.push_back(j); Marc[j] = 1; continue; } une(X, Y); r.push_back(j); } if (poss.size() == 1) {good.push_back(i); continue;} vector<int> res(poss.size()); for (int i = 0; i < poss.size(); i++) { r.push_back(poss[i]); res[i] = count_common_roads(r); r.pop_back(); } int x = *max_element(res.begin(), res.end()); for (int i = 0; i < poss.size(); i++) if (res[i] == x) good.push_back(poss[i]); } return good; }

Compilation message (stderr)

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:22:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     for (int i = 0; i < M && good.size() < n-1; i++)
      |                              ~~~~~~~~~~~~^~~~~
simurgh.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int i = 0; i < poss.size(); i++)
      |                         ~~^~~~~~~~~~~~~
simurgh.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 0; i < poss.size(); i++) if (res[i] == x) good.push_back(poss[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...