Submission #790751

#TimeUsernameProblemLanguageResultExecution timeMemory
790751petezaSimurgh (IOI17_simurgh)C++14
51 / 100
87 ms7500 KiB
#include "simurgh.h" #include <iostream> #include <algorithm> #include <cstring> #include <cassert> using namespace std; using pii = pair<int, int>; int ct, ign; bool vis[505]; vector<pii> adj[505]; vector<int> times[505]; bool checked[50505]; int inside[50505]; 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]); } std::vector<int> inans; int mx = -1; bool once = 0; for(int e:times[ctime]) { if(checked[e]) { if(!inside[e] || once) continue; once = 1; } toask.push_back(e); checked[e] = 1; assert(toask.size() == n-1 && cq++ <= 30000); 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:inans) inside[e] = 1, 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)

In file included from /usr/include/c++/10/cassert:44,
                 from simurgh.cpp:5:
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:60:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |     assert(toask.size() == n-1 && cq++ <= 30000);
      |            ~~~~~~~~~~~~~^~~~~~
#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...