Submission #33860

#TimeUsernameProblemLanguageResultExecution timeMemory
33860mohammad_kilaniSimurgh (IOI17_simurgh)C++14
51 / 100
199 ms5772 KiB
#include "simurgh.h" #include <bits/stdc++.h> using namespace std; const int N = 501; int vis[N] , vi = 0; vector< pair<int,int> > g[N], T[N]; vector< int > ans; bool ok[N * N] = {0} , asked[N * N]; int edge[N] , comp[N]; void gettree(int node,vector<int> &v,int prnt){ vis[node] = vi; edge[node] = prnt; for(int i=0;i<g[node].size();i++){ int newnode = g[node][i].first; if(vis[newnode] != vi){ T[node].push_back(g[node][i]); T[newnode].push_back(make_pair(node,g[node][i].second)); v.push_back(g[node][i].second); gettree(newnode,v,g[node][i].second); } } } void DFS(int node,int cant,int cur){ vis[node] = vi; comp[node] = cur; for(int i=0;i<T[node].size();i++){ int newnode = T[node][i].first; if(vis[newnode] != vi && newnode != cant){ DFS(newnode,cant,cur); } } } std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) { for(int i=0;i<u.size();i++){ g[u[i]].push_back(make_pair(v[i],i)); g[v[i]].push_back(make_pair(u[i],i)); } vi++; vector< int > tree; gettree(0,tree,-1); int res = count_common_roads(tree); for(int i=0;i<n;i++){ if(edge[i] == -1) continue; int cnt = 0 ; vi++; DFS(u[edge[i]],v[edge[i]],0); DFS(v[edge[i]],u[edge[i]],1); int ask = 0 , ask2 = 0 , mx = res ; vector< pair<int,int> > v2; v2.push_back(make_pair(res,edge[i])); for(int j=0;j<u.size();j++){ if(j == edge[i]) continue; if(comp[u[j]] == comp[v[j]]) continue; if(asked[j] && ask == 0){ vector<int> r; for(int k=0;k<tree.size();k++){ if(tree[k] != edge[i]){ r.push_back(tree[k]); } } r.push_back(j); ask2 = count_common_roads(r); if(ok[j]) ask = 1; else ask = 2; } if(asked[j]) continue; vector<int> r; for(int k=0;k<tree.size();k++){ if(tree[k] != edge[i]){ r.push_back(tree[k]); } } r.push_back(j); int cur = count_common_roads(r); v2.push_back(make_pair(cur,j)); mx = max(mx,cur); } if(ask == 0){ for(int j=0;j<v2.size();j++){ asked[v2[j].second] = true; if(v2[j].first == mx) ok[v2[j].second] = true; } } else if(ask == 1){ for(int j=0;j<v2.size();j++){ asked[v2[j].second] = true; if(v2[j].first == ask2) ok[v2[j].second] = true; } } else{ for(int j=0;j<v2.size();j++){ asked[v2[j].second] = true; if(v2[j].first != ask2) ok[v2[j].second] = true; } } } for(int i=0;i<u.size();i++) if(ok[i]) ans.push_back(i); return ans; }

Compilation message (stderr)

simurgh.cpp: In function 'void gettree(int, std::vector<int>&, int)':
simurgh.cpp:15:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[node].size();i++){
               ^
simurgh.cpp: In function 'void DFS(int, int, int)':
simurgh.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<T[node].size();i++){
               ^
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<u.size();i++){
               ^
simurgh.cpp:55:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<u.size();j++){
                ^
simurgh.cpp:60:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k=0;k<tree.size();k++){
                  ^
simurgh.cpp:71:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int k=0;k<tree.size();k++){
                 ^
simurgh.cpp:82:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<v2.size();j++){
                 ^
simurgh.cpp:88:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<v2.size();j++){
                 ^
simurgh.cpp:94:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<v2.size();j++){
                 ^
simurgh.cpp:48:7: warning: unused variable 'cnt' [-Wunused-variable]
   int cnt = 0 ;
       ^
simurgh.cpp:100:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<u.size();i++) if(ok[i]) ans.push_back(i);
               ^
#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...