# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
436679 | 2021-06-24T18:08:48 Z | mat_v | Simurgh (IOI17_simurgh) | C++14 | 987 ms | 20072 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 1 ms | 332 KB | correct |
4 | Correct | 1 ms | 332 KB | correct |
5 | Correct | 1 ms | 332 KB | correct |
6 | Correct | 1 ms | 332 KB | correct |
7 | Correct | 1 ms | 332 KB | correct |
8 | Correct | 1 ms | 332 KB | correct |
9 | Correct | 1 ms | 332 KB | correct |
10 | Correct | 1 ms | 332 KB | correct |
11 | Correct | 1 ms | 332 KB | correct |
12 | Correct | 1 ms | 332 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 1 ms | 332 KB | correct |
4 | Correct | 1 ms | 332 KB | correct |
5 | Correct | 1 ms | 332 KB | correct |
6 | Correct | 1 ms | 332 KB | correct |
7 | Correct | 1 ms | 332 KB | correct |
8 | Correct | 1 ms | 332 KB | correct |
9 | Correct | 1 ms | 332 KB | correct |
10 | Correct | 1 ms | 332 KB | correct |
11 | Correct | 1 ms | 332 KB | correct |
12 | Correct | 1 ms | 332 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
14 | Correct | 5 ms | 460 KB | correct |
15 | Correct | 5 ms | 460 KB | correct |
16 | Correct | 6 ms | 460 KB | correct |
17 | Correct | 3 ms | 332 KB | correct |
18 | Correct | 2 ms | 332 KB | correct |
19 | Correct | 3 ms | 332 KB | correct |
20 | Correct | 3 ms | 332 KB | correct |
21 | Correct | 3 ms | 332 KB | correct |
22 | Correct | 3 ms | 332 KB | correct |
23 | Correct | 2 ms | 332 KB | correct |
24 | Correct | 2 ms | 332 KB | correct |
25 | Correct | 1 ms | 332 KB | correct |
26 | Correct | 2 ms | 332 KB | correct |
27 | Correct | 2 ms | 332 KB | correct |
28 | Correct | 1 ms | 332 KB | correct |
29 | Correct | 1 ms | 332 KB | correct |
30 | Correct | 2 ms | 332 KB | correct |
31 | Correct | 2 ms | 332 KB | correct |
32 | Correct | 2 ms | 332 KB | correct |
33 | Correct | 3 ms | 332 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 1 ms | 332 KB | correct |
4 | Correct | 1 ms | 332 KB | correct |
5 | Correct | 1 ms | 332 KB | correct |
6 | Correct | 1 ms | 332 KB | correct |
7 | Correct | 1 ms | 332 KB | correct |
8 | Correct | 1 ms | 332 KB | correct |
9 | Correct | 1 ms | 332 KB | correct |
10 | Correct | 1 ms | 332 KB | correct |
11 | Correct | 1 ms | 332 KB | correct |
12 | Correct | 1 ms | 332 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
14 | Correct | 5 ms | 460 KB | correct |
15 | Correct | 5 ms | 460 KB | correct |
16 | Correct | 6 ms | 460 KB | correct |
17 | Correct | 3 ms | 332 KB | correct |
18 | Correct | 2 ms | 332 KB | correct |
19 | Correct | 3 ms | 332 KB | correct |
20 | Correct | 3 ms | 332 KB | correct |
21 | Correct | 3 ms | 332 KB | correct |
22 | Correct | 3 ms | 332 KB | correct |
23 | Correct | 2 ms | 332 KB | correct |
24 | Correct | 2 ms | 332 KB | correct |
25 | Correct | 1 ms | 332 KB | correct |
26 | Correct | 2 ms | 332 KB | correct |
27 | Correct | 2 ms | 332 KB | correct |
28 | Correct | 1 ms | 332 KB | correct |
29 | Correct | 1 ms | 332 KB | correct |
30 | Correct | 2 ms | 332 KB | correct |
31 | Correct | 2 ms | 332 KB | correct |
32 | Correct | 2 ms | 332 KB | correct |
33 | Correct | 3 ms | 332 KB | correct |
34 | Correct | 184 ms | 4812 KB | correct |
35 | Correct | 202 ms | 2440 KB | correct |
36 | Correct | 136 ms | 1992 KB | correct |
37 | Correct | 9 ms | 460 KB | correct |
38 | Correct | 213 ms | 2448 KB | correct |
39 | Correct | 180 ms | 2244 KB | correct |
40 | Correct | 134 ms | 1904 KB | correct |
41 | Correct | 148 ms | 4820 KB | correct |
42 | Correct | 209 ms | 2380 KB | correct |
43 | Correct | 113 ms | 1476 KB | correct |
44 | Correct | 99 ms | 1248 KB | correct |
45 | Correct | 115 ms | 1316 KB | correct |
46 | Correct | 77 ms | 1220 KB | correct |
47 | Correct | 41 ms | 748 KB | correct |
48 | Correct | 3 ms | 332 KB | correct |
49 | Correct | 11 ms | 460 KB | correct |
50 | Correct | 34 ms | 716 KB | correct |
51 | Correct | 121 ms | 1348 KB | correct |
52 | Correct | 90 ms | 1184 KB | correct |
53 | Correct | 81 ms | 1100 KB | correct |
54 | Correct | 111 ms | 1496 KB | correct |
55 | Correct | 98 ms | 1352 KB | correct |
56 | Correct | 107 ms | 1380 KB | correct |
57 | Correct | 102 ms | 1288 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 516 ms | 12776 KB | correct |
4 | Correct | 902 ms | 19888 KB | correct |
5 | Correct | 922 ms | 19888 KB | correct |
6 | Correct | 890 ms | 19908 KB | correct |
7 | Correct | 942 ms | 19780 KB | correct |
8 | Correct | 919 ms | 19868 KB | correct |
9 | Correct | 892 ms | 19884 KB | correct |
10 | Correct | 982 ms | 19884 KB | correct |
11 | Correct | 987 ms | 19908 KB | correct |
12 | Correct | 882 ms | 19920 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
14 | Correct | 905 ms | 20072 KB | correct |
15 | Correct | 892 ms | 20008 KB | correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | correct |
2 | Correct | 1 ms | 332 KB | correct |
3 | Correct | 1 ms | 332 KB | correct |
4 | Correct | 1 ms | 332 KB | correct |
5 | Correct | 1 ms | 332 KB | correct |
6 | Correct | 1 ms | 332 KB | correct |
7 | Correct | 1 ms | 332 KB | correct |
8 | Correct | 1 ms | 332 KB | correct |
9 | Correct | 1 ms | 332 KB | correct |
10 | Correct | 1 ms | 332 KB | correct |
11 | Correct | 1 ms | 332 KB | correct |
12 | Correct | 1 ms | 332 KB | correct |
13 | Correct | 1 ms | 332 KB | correct |
14 | Correct | 5 ms | 460 KB | correct |
15 | Correct | 5 ms | 460 KB | correct |
16 | Correct | 6 ms | 460 KB | correct |
17 | Correct | 3 ms | 332 KB | correct |
18 | Correct | 2 ms | 332 KB | correct |
19 | Correct | 3 ms | 332 KB | correct |
20 | Correct | 3 ms | 332 KB | correct |
21 | Correct | 3 ms | 332 KB | correct |
22 | Correct | 3 ms | 332 KB | correct |
23 | Correct | 2 ms | 332 KB | correct |
24 | Correct | 2 ms | 332 KB | correct |
25 | Correct | 1 ms | 332 KB | correct |
26 | Correct | 2 ms | 332 KB | correct |
27 | Correct | 2 ms | 332 KB | correct |
28 | Correct | 1 ms | 332 KB | correct |
29 | Correct | 1 ms | 332 KB | correct |
30 | Correct | 2 ms | 332 KB | correct |
31 | Correct | 2 ms | 332 KB | correct |
32 | Correct | 2 ms | 332 KB | correct |
33 | Correct | 3 ms | 332 KB | correct |
34 | Correct | 184 ms | 4812 KB | correct |
35 | Correct | 202 ms | 2440 KB | correct |
36 | Correct | 136 ms | 1992 KB | correct |
37 | Correct | 9 ms | 460 KB | correct |
38 | Correct | 213 ms | 2448 KB | correct |
39 | Correct | 180 ms | 2244 KB | correct |
40 | Correct | 134 ms | 1904 KB | correct |
41 | Correct | 148 ms | 4820 KB | correct |
42 | Correct | 209 ms | 2380 KB | correct |
43 | Correct | 113 ms | 1476 KB | correct |
44 | Correct | 99 ms | 1248 KB | correct |
45 | Correct | 115 ms | 1316 KB | correct |
46 | Correct | 77 ms | 1220 KB | correct |
47 | Correct | 41 ms | 748 KB | correct |
48 | Correct | 3 ms | 332 KB | correct |
49 | Correct | 11 ms | 460 KB | correct |
50 | Correct | 34 ms | 716 KB | correct |
51 | Correct | 121 ms | 1348 KB | correct |
52 | Correct | 90 ms | 1184 KB | correct |
53 | Correct | 81 ms | 1100 KB | correct |
54 | Correct | 111 ms | 1496 KB | correct |
55 | Correct | 98 ms | 1352 KB | correct |
56 | Correct | 107 ms | 1380 KB | correct |
57 | Correct | 102 ms | 1288 KB | correct |
58 | Correct | 1 ms | 332 KB | correct |
59 | Correct | 1 ms | 332 KB | correct |
60 | Correct | 516 ms | 12776 KB | correct |
61 | Correct | 902 ms | 19888 KB | correct |
62 | Correct | 922 ms | 19888 KB | correct |
63 | Correct | 890 ms | 19908 KB | correct |
64 | Correct | 942 ms | 19780 KB | correct |
65 | Correct | 919 ms | 19868 KB | correct |
66 | Correct | 892 ms | 19884 KB | correct |
67 | Correct | 982 ms | 19884 KB | correct |
68 | Correct | 987 ms | 19908 KB | correct |
69 | Correct | 882 ms | 19920 KB | correct |
70 | Correct | 1 ms | 332 KB | correct |
71 | Correct | 905 ms | 20072 KB | correct |
72 | Correct | 892 ms | 20008 KB | correct |
73 | Correct | 1 ms | 348 KB | correct |
74 | Correct | 891 ms | 20000 KB | correct |
75 | Incorrect | 144 ms | 7748 KB | WA in grader: NO |
76 | Halted | 0 ms | 0 KB | - |