Submission #790665

#TimeUsernameProblemLanguageResultExecution timeMemory
790665petezaSimurgh (IOI17_simurgh)C++14
30 / 100
74 ms3424 KiB
#include "simurgh.h" #include <iostream> #include <algorithm> #include <cstring> using namespace std; using pii = pair<int, int>; int ct, ign; bool vis[505]; vector<pii> adj[505]; vector<int> times[505]; void dfs(int x, vector<int> &to) { for(pii e:adj[x]) { if(e.first == ign) { times[ct].push_back(e.second); continue; } if(vis[e.first]) continue; vis[e.first] = 1; to.push_back(e.second); dfs(e.first, to); } } std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) { std::vector<int> r; int m = u.size(); for(int i=0;i<m;i++) adj[u[i]].emplace_back(v[i], i), adj[v[i]].emplace_back(u[i], i); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) times[j].clear(); //with this node as the main node, generate a spanning tree ignoring this node ign = i; std::vector<int> toask; memset(vis, 0, sizeof vis); vis[i] = 1; for(int j=0;j<n;j++) { ct = j; if(!vis[j]) vis[j] = 1, dfs(j, toask); } int cq = 0; for(int ctime = 0;ctime<n;ctime++) { if(times[ctime].empty()) continue; for(int ktime=0;ktime<n;ktime++) { if(ktime == ctime) continue; if(times[ktime].size()) toask.push_back(times[ktime][0]); //for(int e:times[ktime]) toask.push_back(e); } std::vector<int> inans; int mx = -1; for(int e:times[ctime]) { toask.push_back(e); if(toask.size() >= n) exit(1); int res = count_common_roads(toask); if(res >= mx) { if(res > mx) inans.clear(); mx = res; inans.push_back(e); } toask.pop_back(); } for(int ktime=0;ktime<n;ktime++) { if(ktime == ctime) continue; if(times[ktime].size()) toask.pop_back(); //for(int e:times[ktime]) toask.pop_back(); } for(int e:inans) r.push_back(e); } } sort(r.begin(), r.end()); r.resize(unique(r.begin(), r.end())-r.begin()); return r; } /* 4 6 0 1 0 2 0 3 1 2 1 3 2 3 0 1 5 */

Compilation message (stderr)

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:52:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |     if(toask.size() >= n) exit(1);
      |        ~~~~~~~~~~~~~^~~~
simurgh.cpp:40:7: warning: unused variable 'cq' [-Wunused-variable]
   40 |   int cq = 0;
      |       ^~
#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...