# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
566698 |
2022-05-22T16:47:35 Z |
Uzouf |
Saveit (IOI10_saveit) |
C++14 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
using namespace std;
#include "grader.h"
#include "encoder.h"
void encode(int n,int h,int p,int a[],int b[]) {
for (int i=0;i<N;i++) {
for (int j=0;j<N;j++) {
dis[i][j]=2000;
}
dis[i][i]=0;
}
for (int i=0;i<p;i++) {
v[a[i]].push_back(b[i]);
v[b[i]].push_back(a[i]);
dis[a[i]][b[i]]=dis[b[i]][a[i]]=1;
}
int par[N];
for (int i=0;i<N;i++) par[i]=i;
queue<int> q;
q.push(0); par[0]=-1;
while (!q.empty()) {
int i=q.front();
q.pop();
for (int j:v[i]) {
if (par[j]==j) {
par[j]=i; q.push(j);
}
}
}
//tree:
for (int i=0;i<n;i++) {
if (par[i]==-1) par[i]=i;
for (int pp=0;pp<10;pp++) {
if (((1<<pp)&par[i])==0) encode_bit(0);
else encode_bit(1);
}
}
for (int hub=1;hub<h;hub++) {
//cout<<hub<<":"<<endl;
int dis[N];
bool vis[N];
for (int i=0;i<N;i++) {
vis[i]=false;
}
queue<int> q;
q.push(hub); dis[hub]=0; vis[hub]=true;
while (!q.empty()) {
int i=q.front();
q.pop();
for (int j:v[i]) {
if (!vis[j]) {
vis[j]=true; dis[j]=dis[i]+1; q.push(j);
}
}
}
for (int i=0;i<n;i++) {
int nm=dis[i]-dis[par[i]];
//cout<<i<<' '<<par[i]<<" "<<dis[i]<<' '<<dis[par[i]]<<' '<<nm<<endl;
if (nm==0) {encode_bit(0);continue;}
encode_bit(1);
if (nm==1) encode_bit(0);
else encode_bit(1);
}
}
}
#include <bits/stdc++.h>
using namespace std;
#include "grader.h"
#include "encoder.h"
void decode(int n,int h) {
vector<vector<int> > v(n+5);
int par[n+5];
for (int i=0;i<n;i++) {
int tmp=0;
for (int p=0;p<10;p++) {
tmp+=(decode_bit()*(1<<p));
}
par[i]=tmp;
v[i].push_back(tmp); v[tmp].push_back(i);
}
for (int hub=0;hub<h;hub++) {
int dis[n+5][n+5];
if (hub>0) {
for (int i=0;i<n;i++) {
int tmp=decode_bit();
if (tmp==0) {
dis[i][par[i]]=0; dis[par[i]][i]=0;
}
else {
tmp=decode_bit();
if (tmp==0) {
dis[par[i]][i]=1; dis[i][par[i]]=-1;
}
else {
dis[i][par[i]]=1; dis[par[i]][i]=-1;
}
}
}
}
else {
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) dis[i][j]=1;
}
}
queue<int> q;
int ans[n+5];
bool vis[n+5];
memset(vis,false,sizeof vis);
ans[hub]=0; q.push(hub); vis[hub]=true;
while (!q.empty()) {
int i=q.front();
q.pop();
hops(hub,i,ans[i]);
for (int j:v[i]) {
if (!vis[j]) {
q.push(j); ans[j]=ans[i]+dis[i][j]; vis[j]=true;
}
}
}
}
}
Compilation message
encoder.cpp: In function 'void encode(int, int, int, int*, int*)':
encoder.cpp:8:18: error: 'N' was not declared in this scope
8 | for (int i=0;i<N;i++) {
| ^
encoder.cpp:10:9: error: 'dis' was not declared in this scope; did you mean 'div'?
10 | dis[i][j]=2000;
| ^~~
| div
encoder.cpp:12:7: error: 'dis' was not declared in this scope; did you mean 'div'?
12 | dis[i][i]=0;
| ^~~
| div
encoder.cpp:16:7: error: 'v' was not declared in this scope
16 | v[a[i]].push_back(b[i]);
| ^
encoder.cpp:18:7: error: 'dis' was not declared in this scope; did you mean 'div'?
18 | dis[a[i]][b[i]]=dis[b[i]][a[i]]=1;
| ^~~
| div
encoder.cpp:21:13: error: 'N' was not declared in this scope
21 | int par[N];
| ^
encoder.cpp:22:27: error: 'par' was not declared in this scope
22 | for (int i=0;i<N;i++) par[i]=i;
| ^~~
encoder.cpp:24:16: error: 'par' was not declared in this scope
24 | q.push(0); par[0]=-1;
| ^~~
encoder.cpp:29:18: error: 'v' was not declared in this scope
29 | for (int j:v[i]) {
| ^
encoder.cpp:50:9: error: 'vis' was not declared in this scope
50 | vis[i]=false;
| ^~~
encoder.cpp:53:20: error: 'dis' was not declared in this scope; did you mean 'div'?
53 | q.push(hub); dis[hub]=0; vis[hub]=true;
| ^~~
| div
encoder.cpp:53:32: error: 'vis' was not declared in this scope
53 | q.push(hub); dis[hub]=0; vis[hub]=true;
| ^~~
encoder.cpp:58:20: error: 'v' was not declared in this scope
58 | for (int j:v[i]) {
| ^