#include "art.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
struct dsu{
vector<ll> e;
void init(int n){
e.resize(n+1,-1);
}
int get(int x){
if(e[x]<0){
return x;
}
else{
return e[x]=get(e[x]);
}
}
int size(int x){
return -e[get(x)];
}
bool same_set(int x,int y){
return (get(x)==get(y));
}
bool unite(int x,int y){
x=get(x);
y=get(y);
if(x==y){
return false;
}
if(e[x]>e[y]){
swap(x,y);
}
e[x]+=e[y];
e[y]=x;
return true;
}
};
vector<vector<ll>> g;
vector<ll> used;
vector<ll> indegree;
void dfs(ll v){
used[v]=1;
for(auto x:g[v]){
if(used[x]==0){
dfs(x);
}
}
}
void solve(int N){
g.resize(N+1);
indegree.resize(N+1,0);
vector<int> a;
for(int i=1;i<=N;i++){
for(int j=i+1;j<=N;j++){
used.clear();
used.resize(N+1,0);
dfs(i);
if(used[j]){
continue;
}
used.clear();
used.resize(N+1,0);
dfs(j);
if(used[i]){
continue;
}
a.pb(i);
a.pb(j);
for(int z=1;z<=N;z++){
if(z!=i && z!=j){
a.pb(z);
}
}
ll res1=publish(a);
swap(a[0],a[1]);
ll res2=publish(a);
if(res1<res2){
g[j].pb(i);
indegree[i]++;
}
else{
g[i].pb(j);
indegree[j]++;
}
a.clear();
}
}
queue<ll> q;
for(int i=1;i<=N;i++){
if(indegree[i]==0){
q.push(i);
}
}
while(!q.empty()){
ll v=q.front();
a.pb(v);
q.pop();
for(auto x:g[v]){
indegree[x]--;
if(indegree[x]==0){
q.push(x);
}
}
}
reverse(a.begin(),a.end());
answer(a);
}
Compilation message
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
20 | if(v.size() != N) {
| ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | if(v.size() != N) {
| ~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
6 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
19 ms |
308 KB |
Output is correct |
20 |
Correct |
25 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
6 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
19 ms |
308 KB |
Output is correct |
20 |
Correct |
25 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
5 ms |
304 KB |
Output is correct |
23 |
Correct |
5 ms |
300 KB |
Output is correct |
24 |
Correct |
7 ms |
208 KB |
Output is correct |
25 |
Correct |
6 ms |
208 KB |
Output is correct |
26 |
Incorrect |
132 ms |
556 KB |
Not correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
6 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
19 ms |
308 KB |
Output is correct |
20 |
Correct |
25 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
5 ms |
304 KB |
Output is correct |
23 |
Correct |
5 ms |
300 KB |
Output is correct |
24 |
Correct |
7 ms |
208 KB |
Output is correct |
25 |
Correct |
6 ms |
208 KB |
Output is correct |
26 |
Incorrect |
132 ms |
556 KB |
Not correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
6 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
19 ms |
308 KB |
Output is correct |
20 |
Correct |
25 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
5 ms |
304 KB |
Output is correct |
23 |
Correct |
5 ms |
300 KB |
Output is correct |
24 |
Correct |
7 ms |
208 KB |
Output is correct |
25 |
Correct |
6 ms |
208 KB |
Output is correct |
26 |
Incorrect |
132 ms |
556 KB |
Not correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
6 ms |
300 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
19 ms |
308 KB |
Output is correct |
20 |
Correct |
25 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
208 KB |
Output is correct |
22 |
Correct |
5 ms |
304 KB |
Output is correct |
23 |
Correct |
5 ms |
300 KB |
Output is correct |
24 |
Correct |
7 ms |
208 KB |
Output is correct |
25 |
Correct |
6 ms |
208 KB |
Output is correct |
26 |
Incorrect |
132 ms |
556 KB |
Not correct |
27 |
Halted |
0 ms |
0 KB |
- |