# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
944207 |
2024-03-12T10:14:14 Z |
Wansur |
Simurgh (IOI17_simurgh) |
C++14 |
|
52 ms |
10324 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=500+12;
const bool T=0;
vector<pair<int,int>> g[mx];
vector<vector<int>> ord;
int col[mx][mx];
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, ch=0;
for(int i:cyc){
if(need[i]==1){
ch=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:96:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int l=0;l<cyc.size();l++){
| ~^~~~~~~~~~~
simurgh.cpp:66:25: warning: variable 'ch' set but not used [-Wunused-but-set-variable]
66 | int mn=1e9,mx=-1e9, ch=0;
| ^~
simurgh.cpp: In function 'void dfs(int, int)':
simurgh.cpp:111:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
111 | for(auto [to, i]:g[v]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
456 KB |
correct |
3 |
Correct |
1 ms |
344 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
344 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
344 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
0 ms |
456 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
456 KB |
correct |
3 |
Correct |
1 ms |
344 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
344 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
344 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
0 ms |
456 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Incorrect |
52 ms |
616 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
456 KB |
correct |
3 |
Correct |
1 ms |
344 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
344 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
344 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
0 ms |
456 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Incorrect |
52 ms |
616 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
correct |
2 |
Correct |
1 ms |
344 KB |
correct |
3 |
Runtime error |
28 ms |
10324 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
correct |
2 |
Correct |
0 ms |
456 KB |
correct |
3 |
Correct |
1 ms |
344 KB |
correct |
4 |
Correct |
0 ms |
348 KB |
correct |
5 |
Correct |
0 ms |
344 KB |
correct |
6 |
Correct |
0 ms |
348 KB |
correct |
7 |
Correct |
0 ms |
348 KB |
correct |
8 |
Correct |
0 ms |
348 KB |
correct |
9 |
Correct |
0 ms |
344 KB |
correct |
10 |
Correct |
0 ms |
348 KB |
correct |
11 |
Correct |
0 ms |
456 KB |
correct |
12 |
Correct |
0 ms |
348 KB |
correct |
13 |
Correct |
0 ms |
348 KB |
correct |
14 |
Incorrect |
52 ms |
616 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |