# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
944208 |
2024-03-12T10:21:13 Z |
Wansur |
Simurgh (IOI17_simurgh) |
C++14 |
|
341 ms |
14620 KB |
#include <bits/stdc++.h>
#define f first
#define s second
#define ent '\n'
typedef long long ll;
using namespace std;
struct asd{
int a, b, w, ca, cb;
};
int count_common_roads(const std::vector<int>& r);
int ask(vector<int> r){
return count_common_roads(r);
}
const string out[2]={"NO\n","YES\n"};
const ll dx[]={0,1,0,-1,-1,1,1,-1};
const ll dy[]={1,0,-1,0,-1,1,-1,1};
const int mod=998244353;
const int md=1e9+7;
const int mx=3e5+12;
const bool T=0;
vector<pair<int,int>> g[mx];
vector<vector<int>> ord;
int col[505][505];
vector<int> vv,uu;
bool used[mx];
bool taken[mx];
bool del[mx];
int was[mx];
int need[mx];
int p[mx];
vector<int> cur;
int get(int x){
if(p[x]==x){
return x;
}
return p[x]=get(p[x]);
}
void check(vector<int> &cyc,int n){
int m=vv.size();
for(int i=0;i<n;i++){
p[i]=i;
used[i]=0;
}
for(auto i:cyc){
used[vv[i]]=used[uu[i]]=1;
p[get(vv[i])]=get(uu[i]);
}
vector<int> ost;
for(int i=0;i<m;i++){
if(need[i]==-1){
continue;
}
if(get(vv[i])!=get(uu[i])){
p[get(vv[i])]=get(uu[i]);
ost.push_back(i);
}
}
vector<int> A;
int mn=1e9,mx=-1e9;
for(int i:cyc){
if(need[i]==1){
A.push_back(-1);
continue;
}
vector<int> os;
os=ost;
for(int j:cyc){
if(i!=j){
os.push_back(j);
}
}
int x=ask(os);
mn=min(mn, x);
mx=max(mx, x);
A.push_back(x);
}
for(auto &x:A){
if(x==-1){
x=mn;
}
}
if(mn==mx){
for(int i:cyc){
if(need[i]!=1)need[i]=-1;
}
return;
}
for(int l=0;l<cyc.size();l++){
int i=cyc[l];
if(A[l]==mx){
need[i]=-1;
}
else{
need[i]=1;
}
}
}
void dfs(int v,int p){
was[v]=1;
cur.push_back(v);
int cyc=-1;
for(auto [to, i]:g[v]){
if(to==p || need[i]==-1)continue;
if(was[to]==1 && !taken[to]){
cyc=to;
}
if(!was[to]){
dfs(to, v);
}
}
if(cyc!=-1){
bool ok=0;
int pos=cur.size()-1;
for(int i=cur.size()-1;;i--){
if(taken[cur[i]]){
ok=1;
}
if(cur[i]==cyc){
pos=i;
break;
}
}
if(ok){
cur.pop_back();
was[v]=2;
return;
}
vector<int> cc;
for(int i=cur.size()-1;i>=pos;i--){
taken[cur[i]]=1;
if(i>pos){
cc.push_back(col[cur[i]][cur[i-1]]);
}
}
cc.push_back(col[v][cyc]);
ord.push_back(cc);
}
cur.pop_back();
was[v]=2;
}
bool dec(int n,int m){
ord.clear();
cur.clear();
for(int i=0;i<n;i++){
was[i]=0;
taken[i]=0;
}
for(int i=0;i<n;i++){
if(!was[i]){
dfs(i, -1);
}
}
if(ord.size()==0){
return 0;
}
for(auto &cyc:ord){
check(cyc, n);
}
return 1;
}
vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v){
int m=u.size();
vv=v, uu=u;
for(int i=0;i<m;i++){
g[v[i]].push_back({u[i], i});
g[u[i]].push_back({v[i], i});
col[v[i]][u[i]]=col[u[i]][v[i]]=i;
}
while(dec(n, m));
vector<int> ans;
for(int i=0;i<n;i++){
p[i]=i;
}
for(int i=0;i<m;i++){
if(need[i]==1){
ans.push_back(i);
p[get(v[i])]=get(u[i]);
}
}
for(int i=0;i<m;i++){
if(get(v[i])!=get(u[i]) && need[i]!=-1){
ans.push_back(i);
p[get(v[i])]=get(u[i]);
}
}
return ans;
}
Compilation message
simurgh.cpp: In function 'void check(std::vector<int>&, int)':
simurgh.cpp:95:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int l=0;l<cyc.size();l++){
| ~^~~~~~~~~~~
simurgh.cpp: In function 'void dfs(int, int)':
simurgh.cpp:110:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
110 | for(auto [to, i]:g[v]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
correct |
2 |
Correct |
3 ms |
10588 KB |
correct |
3 |
Correct |
5 ms |
10588 KB |
correct |
4 |
Correct |
2 ms |
10588 KB |
correct |
5 |
Correct |
2 ms |
10588 KB |
correct |
6 |
Correct |
3 ms |
10588 KB |
correct |
7 |
Correct |
3 ms |
10588 KB |
correct |
8 |
Correct |
3 ms |
10588 KB |
correct |
9 |
Correct |
3 ms |
10588 KB |
correct |
10 |
Correct |
2 ms |
10588 KB |
correct |
11 |
Correct |
3 ms |
10588 KB |
correct |
12 |
Correct |
3 ms |
10592 KB |
correct |
13 |
Correct |
3 ms |
10588 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
correct |
2 |
Correct |
3 ms |
10588 KB |
correct |
3 |
Correct |
5 ms |
10588 KB |
correct |
4 |
Correct |
2 ms |
10588 KB |
correct |
5 |
Correct |
2 ms |
10588 KB |
correct |
6 |
Correct |
3 ms |
10588 KB |
correct |
7 |
Correct |
3 ms |
10588 KB |
correct |
8 |
Correct |
3 ms |
10588 KB |
correct |
9 |
Correct |
3 ms |
10588 KB |
correct |
10 |
Correct |
2 ms |
10588 KB |
correct |
11 |
Correct |
3 ms |
10588 KB |
correct |
12 |
Correct |
3 ms |
10592 KB |
correct |
13 |
Correct |
3 ms |
10588 KB |
correct |
14 |
Correct |
6 ms |
10588 KB |
correct |
15 |
Correct |
5 ms |
10588 KB |
correct |
16 |
Correct |
5 ms |
10588 KB |
correct |
17 |
Correct |
5 ms |
10676 KB |
correct |
18 |
Correct |
3 ms |
10588 KB |
correct |
19 |
Correct |
5 ms |
10668 KB |
correct |
20 |
Correct |
5 ms |
10588 KB |
correct |
21 |
Correct |
5 ms |
10684 KB |
correct |
22 |
Correct |
4 ms |
10588 KB |
correct |
23 |
Correct |
4 ms |
10588 KB |
correct |
24 |
Correct |
5 ms |
10588 KB |
correct |
25 |
Correct |
3 ms |
10664 KB |
correct |
26 |
Correct |
5 ms |
10588 KB |
correct |
27 |
Correct |
6 ms |
10720 KB |
correct |
28 |
Correct |
3 ms |
10584 KB |
correct |
29 |
Correct |
3 ms |
10584 KB |
correct |
30 |
Correct |
4 ms |
10588 KB |
correct |
31 |
Correct |
4 ms |
10588 KB |
correct |
32 |
Correct |
4 ms |
10588 KB |
correct |
33 |
Correct |
4 ms |
10680 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
correct |
2 |
Correct |
3 ms |
10588 KB |
correct |
3 |
Correct |
5 ms |
10588 KB |
correct |
4 |
Correct |
2 ms |
10588 KB |
correct |
5 |
Correct |
2 ms |
10588 KB |
correct |
6 |
Correct |
3 ms |
10588 KB |
correct |
7 |
Correct |
3 ms |
10588 KB |
correct |
8 |
Correct |
3 ms |
10588 KB |
correct |
9 |
Correct |
3 ms |
10588 KB |
correct |
10 |
Correct |
2 ms |
10588 KB |
correct |
11 |
Correct |
3 ms |
10588 KB |
correct |
12 |
Correct |
3 ms |
10592 KB |
correct |
13 |
Correct |
3 ms |
10588 KB |
correct |
14 |
Correct |
6 ms |
10588 KB |
correct |
15 |
Correct |
5 ms |
10588 KB |
correct |
16 |
Correct |
5 ms |
10588 KB |
correct |
17 |
Correct |
5 ms |
10676 KB |
correct |
18 |
Correct |
3 ms |
10588 KB |
correct |
19 |
Correct |
5 ms |
10668 KB |
correct |
20 |
Correct |
5 ms |
10588 KB |
correct |
21 |
Correct |
5 ms |
10684 KB |
correct |
22 |
Correct |
4 ms |
10588 KB |
correct |
23 |
Correct |
4 ms |
10588 KB |
correct |
24 |
Correct |
5 ms |
10588 KB |
correct |
25 |
Correct |
3 ms |
10664 KB |
correct |
26 |
Correct |
5 ms |
10588 KB |
correct |
27 |
Correct |
6 ms |
10720 KB |
correct |
28 |
Correct |
3 ms |
10584 KB |
correct |
29 |
Correct |
3 ms |
10584 KB |
correct |
30 |
Correct |
4 ms |
10588 KB |
correct |
31 |
Correct |
4 ms |
10588 KB |
correct |
32 |
Correct |
4 ms |
10588 KB |
correct |
33 |
Correct |
4 ms |
10680 KB |
correct |
34 |
Correct |
308 ms |
12252 KB |
correct |
35 |
Correct |
304 ms |
12120 KB |
correct |
36 |
Correct |
160 ms |
11868 KB |
correct |
37 |
Correct |
8 ms |
10588 KB |
correct |
38 |
Correct |
341 ms |
12264 KB |
correct |
39 |
Correct |
190 ms |
12100 KB |
correct |
40 |
Correct |
128 ms |
11908 KB |
correct |
41 |
Correct |
173 ms |
12236 KB |
correct |
42 |
Correct |
172 ms |
12124 KB |
correct |
43 |
Correct |
230 ms |
11612 KB |
correct |
44 |
Correct |
158 ms |
11432 KB |
correct |
45 |
Correct |
210 ms |
11356 KB |
correct |
46 |
Correct |
126 ms |
11100 KB |
correct |
47 |
Correct |
41 ms |
10844 KB |
correct |
48 |
Correct |
5 ms |
10584 KB |
correct |
49 |
Correct |
10 ms |
10840 KB |
correct |
50 |
Correct |
45 ms |
10844 KB |
correct |
51 |
Correct |
199 ms |
11356 KB |
correct |
52 |
Correct |
180 ms |
11376 KB |
correct |
53 |
Correct |
159 ms |
11096 KB |
correct |
54 |
Correct |
237 ms |
11688 KB |
correct |
55 |
Correct |
168 ms |
11504 KB |
correct |
56 |
Correct |
162 ms |
11480 KB |
correct |
57 |
Correct |
175 ms |
11508 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
correct |
2 |
Correct |
3 ms |
10588 KB |
correct |
3 |
Incorrect |
135 ms |
14620 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
correct |
2 |
Correct |
3 ms |
10588 KB |
correct |
3 |
Correct |
5 ms |
10588 KB |
correct |
4 |
Correct |
2 ms |
10588 KB |
correct |
5 |
Correct |
2 ms |
10588 KB |
correct |
6 |
Correct |
3 ms |
10588 KB |
correct |
7 |
Correct |
3 ms |
10588 KB |
correct |
8 |
Correct |
3 ms |
10588 KB |
correct |
9 |
Correct |
3 ms |
10588 KB |
correct |
10 |
Correct |
2 ms |
10588 KB |
correct |
11 |
Correct |
3 ms |
10588 KB |
correct |
12 |
Correct |
3 ms |
10592 KB |
correct |
13 |
Correct |
3 ms |
10588 KB |
correct |
14 |
Correct |
6 ms |
10588 KB |
correct |
15 |
Correct |
5 ms |
10588 KB |
correct |
16 |
Correct |
5 ms |
10588 KB |
correct |
17 |
Correct |
5 ms |
10676 KB |
correct |
18 |
Correct |
3 ms |
10588 KB |
correct |
19 |
Correct |
5 ms |
10668 KB |
correct |
20 |
Correct |
5 ms |
10588 KB |
correct |
21 |
Correct |
5 ms |
10684 KB |
correct |
22 |
Correct |
4 ms |
10588 KB |
correct |
23 |
Correct |
4 ms |
10588 KB |
correct |
24 |
Correct |
5 ms |
10588 KB |
correct |
25 |
Correct |
3 ms |
10664 KB |
correct |
26 |
Correct |
5 ms |
10588 KB |
correct |
27 |
Correct |
6 ms |
10720 KB |
correct |
28 |
Correct |
3 ms |
10584 KB |
correct |
29 |
Correct |
3 ms |
10584 KB |
correct |
30 |
Correct |
4 ms |
10588 KB |
correct |
31 |
Correct |
4 ms |
10588 KB |
correct |
32 |
Correct |
4 ms |
10588 KB |
correct |
33 |
Correct |
4 ms |
10680 KB |
correct |
34 |
Correct |
308 ms |
12252 KB |
correct |
35 |
Correct |
304 ms |
12120 KB |
correct |
36 |
Correct |
160 ms |
11868 KB |
correct |
37 |
Correct |
8 ms |
10588 KB |
correct |
38 |
Correct |
341 ms |
12264 KB |
correct |
39 |
Correct |
190 ms |
12100 KB |
correct |
40 |
Correct |
128 ms |
11908 KB |
correct |
41 |
Correct |
173 ms |
12236 KB |
correct |
42 |
Correct |
172 ms |
12124 KB |
correct |
43 |
Correct |
230 ms |
11612 KB |
correct |
44 |
Correct |
158 ms |
11432 KB |
correct |
45 |
Correct |
210 ms |
11356 KB |
correct |
46 |
Correct |
126 ms |
11100 KB |
correct |
47 |
Correct |
41 ms |
10844 KB |
correct |
48 |
Correct |
5 ms |
10584 KB |
correct |
49 |
Correct |
10 ms |
10840 KB |
correct |
50 |
Correct |
45 ms |
10844 KB |
correct |
51 |
Correct |
199 ms |
11356 KB |
correct |
52 |
Correct |
180 ms |
11376 KB |
correct |
53 |
Correct |
159 ms |
11096 KB |
correct |
54 |
Correct |
237 ms |
11688 KB |
correct |
55 |
Correct |
168 ms |
11504 KB |
correct |
56 |
Correct |
162 ms |
11480 KB |
correct |
57 |
Correct |
175 ms |
11508 KB |
correct |
58 |
Correct |
2 ms |
10588 KB |
correct |
59 |
Correct |
3 ms |
10588 KB |
correct |
60 |
Incorrect |
135 ms |
14620 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |