Submission #1113022

#TimeUsernameProblemLanguageResultExecution timeMemory
1113022SalihSahinSimurgh (IOI17_simurgh)C++14
0 / 100
77 ms3664 KiB
#include <bits/stdc++.h> #define pb push_back #include "simurgh.h" using namespace std; /* static int MAXQ = 30000; static int n, m, q = 0; static vector<int> u, v; static vector<bool> goal; static void wrong_answer() { printf("NO\n"); exit(0); } static bool is_valid(const vector<int>& r) { if(int(r.size()) != n - 1) return false; for(int i = 0; i < n - 1; i++) if (r[i] < 0 || r[i] >= m) return false; return true; } static int _count_common_roads_internal(const vector<int>& r) { if(!is_valid(r)) wrong_answer(); int common = 0; for(int i = 0; i < n - 1; i++) { bool is_common = goal[r[i]]; if (is_common) common++; } return common; } int count_common_roads(const vector<int>& r) { q++; if(q > MAXQ) wrong_answer(); return _count_common_roads_internal(r); } */ const int MAXN = 5e2 + 5; vector<int> par(MAXN); vector<pair<int, int> > adj[MAXN]; int fnd(int a){ if(a == par[a]) return a; return par[a] = fnd(par[a]); } void merge(int a, int b){ a = fnd(a), b = fnd(b); par[b] = a; } vector<int> find_roads(int n, vector<int> u, vector<int> v) { vector<int> r; int m = u.size(); vector<int> ok(m); for(int i = 0; i < m; i++){ adj[u[i]].pb({v[i], i}); adj[v[i]].pb({u[i], i}); } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ par[j] = j; } vector<int> ottree; for(int j = 0; j < n; j++){ if(j == i) continue; for(auto itr: adj[j]){ if(itr.first == i) continue; if(fnd(j) == fnd(itr.first)) continue; ottree.pb(itr.second); merge(j, itr.first); } } // diğerlerini olabildiğince mergeledik if(ottree.size() == n-2){ vector<pair<int, int> > vals; int mx = 0; for(auto itr: adj[i]){ ottree.pb(itr.second); int cnt = count_common_roads(ottree); vals.pb({cnt, itr.second}); mx = max(mx, cnt); ottree.pop_back(); } for(auto itr: vals){ if(itr.first == mx){ ok[itr.second] = 1; } } } else{ // a tane grup olsun a-1 tanesini random seçip a. gruptakileri dene büyük olanları tagle sonra random birini seçip a-1. için aynı şeyi yap vector<pair<int, int> > edge; set<int> df; for(auto itr: adj[i]){ edge.pb({fnd(itr.first), itr.second}); df.insert(fnd(itr.first)); } sort(edge.begin(), edge.end()); vector<int> groups[df.size()]; int x = *(df.begin()); int ind = 0; for(auto itr: edge){ if(itr.first != x){ ind++; x = itr.first; } groups[ind].pb(itr.second); } for(int g = 0; g < df.size(); g++){ for(int g2 = 0; g2 < df.size(); g2++){ if(g2 == g) continue; ottree.pb(groups[g2][0]); } set<int> cntv; vector<pair<int, int> > vals; int mx = 0; for(auto itr: groups[g]){ ottree.pb(itr); int cnt = count_common_roads(ottree); cntv.insert(cnt); vals.pb({cnt, itr}); mx = max(mx, cnt); ottree.pop_back(); } if(cntv.size() > 1){ for(int j = 0; j < vals.size(); j++){ if(vals[j].first == mx) ok[vals[j].second] = 1; } } for(int g2 = 0; g2 < df.size(); g2++){ if(g2 == g) continue; ottree.pop_back(); } } } } for(int i = 0; i < m; i++){ if(ok[i]) r.pb(i); } return r; } /* int main() { assert(2 == scanf("%d %d", &n, &m)); u.resize(m); v.resize(m); for(int i = 0; i < m; i++) assert(2 == scanf("%d %d", &u[i], &v[i])); goal.resize(m, false); for(int i = 0; i < n - 1; i++) { int id; assert(1 == scanf("%d", &id)); goal[id] = true; } vector<int> res = find_roads(n, u, v); for(auto itr: res){ cout<<itr<<" "; } cout<<endl; if(_count_common_roads_internal(res) != n - 1) wrong_answer(); printf("YES\n"); return 0; }*/

Compilation message (stderr)

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:89:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   89 |       if(ottree.size() == n-2){
      |          ~~~~~~~~~~~~~~^~~~~~
simurgh.cpp:125:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |          for(int g = 0; g < df.size(); g++){
      |                         ~~^~~~~~~~~~~
simurgh.cpp:126:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |             for(int g2 = 0; g2 < df.size(); g2++){
      |                             ~~~^~~~~~~~~~~
simurgh.cpp:145:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  145 |                for(int j = 0; j < vals.size(); j++){
      |                               ~~^~~~~~~~~~~~~
simurgh.cpp:150:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |             for(int g2 = 0; g2 < df.size(); g2++){
      |                             ~~~^~~~~~~~~~~
#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...