Submission #436679

#TimeUsernameProblemLanguageResultExecution timeMemory
436679mat_vSimurgh (IOI17_simurgh)C++14
70 / 100
987 ms20072 KiB
#include "simurgh.h" #include <bits/stdc++.h> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define pb push_back #define pii pair<int,int> #define xx first #define yy second using namespace std; pii ed[500005]; int _n; int disc[505]; bool bio[505]; vector<pii> graf[505]; pii cale[505]; vector<pii> gore[505]; int br=1; int odg[500005]; int out[505]; int Q; bool jbt; void dfs(int x){ disc[x] = br; bio[x] = 1; for(auto c:graf[x]){ if(bio[c.xx])continue; cale[c.xx] = {x,c.yy}; br++; dfs(c.xx); } br++; out[x] = br; } set<int> s; int poc; int dsu[505]; int finddsu(int x){ if(x == dsu[x])return x; return dsu[x] = finddsu(dsu[x]); } int pitaj(){ int pppp = s.size(); //if(pppp == _n)assert(false); if(jbt)Q++; if(Q > 12000)assert(false); vector<int> r; for(auto c:s)r.pb(c); ff(i,0,_n-1)dsu[i] = i; // for(auto c:r){ // if(finddsu(ed[c].xx) == finddsu(ed[c].yy))assert(false); // dsu[finddsu(ed[c].xx)] = finddsu(ed[c].yy); // } return count_common_roads(r); } vector<pii> sad; vector<int> ans; vector<int> imam; void resi(int x){ for(auto c:graf[x]){ if(cale[c.xx].xx == x)resi(c.xx); } if(x == 0)return; int i = x; sad.clear(); int mks = poc; sad.pb({poc,cale[i].yy}); bool da = 0; for(auto c:gore[i]){ s.erase(cale[i].yy); s.insert(c.yy); int sta = pitaj(); if(sta != poc)da = 1; mks = max(mks, sta); sad.pb({sta, c.yy}); s.erase(c.yy); s.insert(cale[i].yy); } if(da){ for(auto c:sad){ if(c.xx == mks){ ans.pb(c.yy); odg[c.yy] = 1; } } } else{ bool ima = 0; for(auto c:imam){ int mn = min(disc[ed[c].xx], disc[ed[c].yy]); int ms = max(disc[ed[c].xx], disc[ed[c].yy]); if(mn < disc[x] && ms > disc[x] && ms < out[x]){ ima = 1; s.erase(cale[i].yy); s.insert(c); int kurac = pitaj(); if(kurac == poc){ odg[cale[i].yy] = odg[c]; } else if(kurac < poc)odg[cale[i].yy] = 1; s.erase(c); s.insert(cale[i].yy); break; } } if(!ima)odg[cale[i].yy] = 1; if(odg[cale[i].yy] == 1){ for(auto c:sad){ odg[c.yy] = 1; ans.pb(c.yy); } } } for(auto c:gore[i])imam.pb(c.yy); } map<pii,int> koji; int deg[505]; int glava; vector<int> cigani[505]; bool has[505]; bool ABC[505]; std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) { //std::vector<int> r(n - 1); int m = u.size(); if(2 * m == (n * (n - 1))){ _n = n; jbt = 1; ff(i,0,m - 1)ed[i] = {u[i], v[i]}; if(n == 2){ vector<int> r; r.pb(0); return r; } ff(i,0,m - 1)koji[{u[i],v[i]}] = koji[{v[i],u[i]}] = i; //cout << "SHEEESH\n"; ff(i,0,n - 1){ s.clear(); ff(j,0,n - 1){ if(i == j)continue; s.insert(koji[{i,j}]); } deg[i] = pitaj(); } s.clear(); int g = 0; ff(i,0,n - 1){ if(deg[i] == 1)g = i; } int last = -1; ff(i,0,n - 1){ if(i == g)continue; if(last == -1)last = i; else{ s.insert(koji[{last,i}]); } last = i; } s.insert(koji[{g,(g+1)%n}]); int ms = pitaj(); s.erase(koji[{g,(g+1)%n}]); int idx = (g+1)%n; ff(i,0,n - 1){ if(i == g)continue; s.insert(koji[{g,i}]); int sta = pitaj(); if(sta > ms){ ms = sta; idx = i; } s.erase(koji[{g,i}]); } glava = idx; //cout << glava << "\n"; cigani[glava].pb(g); ans.pb(koji[{glava,g}]); stack<int> q; ff(i,0,n - 1){ if(deg[i] == 1)q.push(i); } while(!q.empty()){ int sta = q.top(); //if(ABC[sta])assert(false); //cout << sta << "\n"; ABC[sta] = 1; q.pop(); if(deg[sta] == 0)break; //cout << sta << "\n"; //exit(0); if(sta == g){ deg[glava]--; if(deg[glava] == 1){ q.push(glava); } continue; } s.clear(); s.insert(koji[{g,sta}]); vector<int> ost; ff(i,0,n - 1)has[i] = 0; has[sta] = 1; has[g] = 1; for(auto c:cigani[sta])has[c] = 1; ff(i,0,n - 1){ if(!has[i])ost.pb(i); } int l = 0; int r = ost.size(); int dz = ost.size(); if(l >= r)break; r--; while(l < r){ int mid = (l + r) / 2; s.clear(); s.insert(koji[{g,sta}]); ff(i,l,mid){ s.insert(koji[{sta,ost[i]}]); } int dlt = 0; ff(i,0,dz - 1){ if(i >= l && i <= mid)continue; if(ost[i] == g)continue; s.insert(koji[{g,ost[i]}]); if(ost[i] == glava)dlt++; } for(auto c:cigani[sta]){ if(c == g)continue; s.insert(koji[{g,c}]); if(c == glava)dlt++; } int molim = pitaj(); if(sta == glava)dlt++; molim -= dlt; assert(molim <= 1 && molim >= 0); if(molim == 1){ r = mid; } else l = mid + 1; } //cout << sta << " " << ost[l] << "\n"; int tata = ost[l]; cigani[tata].pb(sta); deg[tata]--; if(deg[tata] == 1)q.push(tata); ans.pb(koji[{tata,sta}]); } s.clear(); for(auto c:ans)s.insert(c); int qrac = ans.size(); if(qrac == n)assert(false); pitaj(); return ans; } _n = n; ff(i,0,m - 1){ ed[i] = {u[i],v[i]}; graf[u[i]].pb({v[i],i}); graf[v[i]].pb({u[i],i}); } ff(i,0,n - 1)cale[i].xx = -1; dfs(0); ff(i,0,m - 1){ int prvi = u[i]; int drugi = v[i]; if(cale[prvi].xx == drugi || cale[drugi].xx == prvi)continue; if(disc[prvi] < disc[drugi]){ gore[drugi].pb({prvi,i}); } else gore[prvi].pb({drugi,i}); } ff(i,0,m - 1){ if(cale[u[i]].xx == v[i] || cale[v[i]].xx == u[i])s.insert(i); } //cout << "kurcina\n"; poc = pitaj(); resi(0); int pp = ans.size(); //assert(pp == n-1); return ans; } /* 4 6 0 1 0 2 0 3 1 2 1 3 2 3 0 1 5 */

Compilation message (stderr)

simurgh.cpp: In function 'int pitaj()':
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:55:5: note: in expansion of macro 'ff'
   55 |     ff(i,0,_n-1)dsu[i] = i;
      |     ^~
simurgh.cpp:49:9: warning: unused variable 'pppp' [-Wunused-variable]
   49 |     int pppp = s.size();
      |         ^~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:142:9: note: in expansion of macro 'ff'
  142 |         ff(i,0,m - 1)ed[i] = {u[i], v[i]};
      |         ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:148:9: note: in expansion of macro 'ff'
  148 |         ff(i,0,m - 1)koji[{u[i],v[i]}] = koji[{v[i],u[i]}] = i;
      |         ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:151:9: note: in expansion of macro 'ff'
  151 |         ff(i,0,n - 1){
      |         ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:153:13: note: in expansion of macro 'ff'
  153 |             ff(j,0,n - 1){
      |             ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:162:9: note: in expansion of macro 'ff'
  162 |         ff(i,0,n - 1){
      |         ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:166:9: note: in expansion of macro 'ff'
  166 |         ff(i,0,n - 1){
      |         ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:178:9: note: in expansion of macro 'ff'
  178 |         ff(i,0,n - 1){
      |         ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:193:9: note: in expansion of macro 'ff'
  193 |         ff(i,0,n - 1){
      |         ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:217:13: note: in expansion of macro 'ff'
  217 |             ff(i,0,n - 1)has[i] = 0;
      |             ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:221:13: note: in expansion of macro 'ff'
  221 |             ff(i,0,n - 1){
      |             ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:233:17: note: in expansion of macro 'ff'
  233 |                 ff(i,l,mid){
      |                 ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:237:17: note: in expansion of macro 'ff'
  237 |                 ff(i,0,dz - 1){
      |                 ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:272:5: note: in expansion of macro 'ff'
  272 |     ff(i,0,m - 1){
      |     ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:277:5: note: in expansion of macro 'ff'
  277 |     ff(i,0,n - 1)cale[i].xx = -1;
      |     ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:279:5: note: in expansion of macro 'ff'
  279 |     ff(i,0,m - 1){
      |     ^~
simurgh.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
simurgh.cpp:288:5: note: in expansion of macro 'ff'
  288 |     ff(i,0,m - 1){
      |     ^~
simurgh.cpp:294:9: warning: unused variable 'pp' [-Wunused-variable]
  294 |     int pp = ans.size();
      |         ^~
#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...