Submission #1113020

#TimeUsernameProblemLanguageResultExecution timeMemory
1113020SalihSahinSimurgh (IOI17_simurgh)C++14
0 / 100
73 ms3852 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); } } 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; } } } } 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:88:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |       if(ottree.size() == n-2){
      |          ~~~~~~~~~~~~~~^~~~~~
#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...