Submission #127668

#TimeUsernameProblemLanguageResultExecution timeMemory
127668MasterdanSimurgh (IOI17_simurgh)C++14
13 / 100
36 ms4984 KiB
#include "simurgh.h" #include <bits/stdc++.h> #define MIN -1 #define MAX 1000000000 #define pb push_back #define mp make _pair #define all(a) a.begin (), a.end () using namespace std; typedef long long int ll; typedef vector <int> vi; int p[300]; int m,n; bool aux[300]; vector<pair<int,int>> g[500]; vector<int> u,v; int findset(int x){ return x == p[x] ? x : p[x]=findset(p[x]); } bool initset(vector<int> ans){ for(int i=0;i<n;i++) p[i] = i; for(int i=0;i<ans.size();i++){ int id = ans[i]; int a = u[id]; int b = v[id]; if(findset(a) == findset(b)) continue; p[findset(b)] = findset(a); } for(int i=0;i<n;i++){ if(findset(i) != findset(0)) return 0;} return 1; } vector<int> find_roads(int N, vector<int> U, vector<int> V) { vector<int> ans; u = U; v = V; n = N; m = u.size(); for(int i=0;i<n;i++) p[i] = i; int lst; for(int i=0;i<m;i++){ int a = u[i]; int b = v[i]; g[a].push_back({b,i}); g[b].push_back({a,i}); if(findset(a) == findset(b)) continue; aux[i] = 1; ans.push_back(i); p[findset(b)] = findset(a); } lst = count_common_roads(ans); for(int i=0;i<ans.size();i++){ int id = ans[i]; int a = u[id]; int b = v[id]; for(int j=0;j<m;j++){ if(aux[j]) continue; ans[i] = j; if(initset(ans) == 1){ int r = count_common_roads(ans); if(r < lst){ ans[i] = id; break; } if(r > lst){ lst = r; aux[j] = 1; aux[id] = 0; break; } } ans[i] = id; } } return ans; }

Compilation message (stderr)

simurgh.cpp: In function 'bool initset(std::vector<int>)':
simurgh.cpp:25:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++){
              ~^~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:62:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++){
              ~^~~~~~~~~~~
simurgh.cpp:64:7: warning: unused variable 'a' [-Wunused-variable]
   int a = u[id];
       ^
simurgh.cpp:65:7: warning: unused variable 'b' [-Wunused-variable]
   int b = v[id];
       ^
#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...