답안 #27147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27147 2017-07-09T14:43:19 Z top34051 Amusement Park (JOI17_amusement_park) C++14
컴파일 오류
0 ms 0 KB
#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
int cnt;
int bit[10005];
int val[65];
bool vis[10005];
bool ok[10005];
vector<int> from[10005];
set<int> st;
set<int> p[10005];
set<int> leaf[10005];
queue<int> q;
void dfs(int x) {
    int i;
    if(cnt>=60) return ;
    ok[x] = 1;
    bit[x] = cnt++;
    for(i=0;i<from[x].size();i++) {
        if(bit[from[x][i]]==-1 && cnt<60) {
            ok[x] = 0;
            dfs(from[x][i]);
        }
    }
}
void give(int x,int y) {
    int i,k;
    set<int>::iterator it;
    for(it=leaf[y].begin();it!=leaf[y].end();it++) if(*it!=y) k = *it;
    bit[x] = bit[k];
    p[x] = p[y]; leaf[x] = leaf[y];
    p[x].erase(k); p[x].insert(x);
    leaf[x].erase(k); leaf[x].insert(x);
}
void go(int x,int last,int P) {
    int i;
    vis[x] = 1;
    for(i=0;i<from[x].size();i++) if(p[P].find(from[x][i])!=p[P].end() && !vis[from[x][i]]) val[from[x][i]] = Move(from[x][i]), go(from[x][i],x,P);
    if(last!=-1) val[last] = Move(last);
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
    int i,j,x,y,zr;
    long long ans;
    set<int>::iterator it;
    for(i=0;i<M;i++) from[A[i]].push_back(B[i]), from[B[i]].push_back(A[i]);
    for(i=0;i<M;i++) if(from[i].size()>1) zr = i;
    //Build graph
    memset(bit,-1,sizeof(bit));
    dfs(zr);
    //All nodes
    st.clear();
    for(i=0;i<N;i++) if(bit[i]!=-1) st.insert(i);
    for(i=0;i<N;i++) if(bit[i]!=-1) p[i] = st;
    //All leaves
    st.clear();
    for(i=0;i<N;i++) if(bit[i]!=-1 && ok[i]) st.insert(i);
    for(i=0;i<N;i++) if(bit[i]!=-1) leaf[i] = st;
    //BFS
    memset(vis,0,sizeof(vis));
    for(i=0;i<N;i++) if(bit[i]!=-1) vis[i] = 1, q.push(i);
    while(!q.empty()) {
        x = q.front(); q.pop();
        for(i=0;i<from[x].size();i++) {
            y = from[x][i];
//            printf("-- BFS %d -> %d\n",x,y);
            if(!vis[y]) {
                vis[y] = 1;
                give(y,x);
                q.push(y);
            }
        }
    }
    //Walk
    memset(vis,0,sizeof(vis));
    go(P,-1,P);
    //Answer
    ans = 0;
    for(it=p[P].begin();it!=p[P].end();it++) ans += (long long)(1LL<<bit[*it]) * val[*it];
    return ans;
}
#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
int cnt;
int bit[10005];
int val[65];
bool vis[10005];
bool ok[10005];
vector<int> from[10005];
set<int> st;
set<int> p[10005];
set<int> leaf[10005];
queue<int> q;
void dfs(int x) {
    int i;
    if(cnt>=60) return ;
    ok[x] = 1;
    bit[x] = cnt++;
    for(i=0;i<from[x].size();i++) {
        if(bit[from[x][i]]==-1 && cnt<60) {
            ok[x] = 0;
            dfs(from[x][i]);
        }
    }
}
void give(int x,int y) {
    int i,k;
    set<int>::iterator it;
    for(it=leaf[y].begin();it!=leaf[y].end();it++) if(*it!=y) k = *it;
    bit[x] = bit[k];
    p[x] = p[y]; leaf[x] = leaf[y];
    p[x].erase(k); p[x].insert(x);
    leaf[x].erase(k); leaf[x].insert(x);
}
void go(int x,int last,int P) {
    int i;
    vis[x] = 1;
    for(i=0;i<from[x].size();i++) if(p[P].find(from[x][i])!=p[P].end() && !vis[from[x][i]]) val[from[x][i]] = Move(from[x][i]), go(from[x][i],x,P);
    if(last!=-1) val[last] = Move(last);
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
    int i,j,x,y,zr;
    long long ans;
    set<int>::iterator it;
    for(i=0;i<M;i++) from[A[i]].push_back(B[i]), from[B[i]].push_back(A[i]);
    for(i=0;i<M;i++) if(from[i].size()>1) zr = i;
    //Build graph
    memset(bit,-1,sizeof(bit));
    dfs(zr);
    //All nodes
    st.clear();
    for(i=0;i<N;i++) if(bit[i]!=-1) st.insert(i);
    for(i=0;i<N;i++) if(bit[i]!=-1) p[i] = st;
    //All leaves
    st.clear();
    for(i=0;i<N;i++) if(bit[i]!=-1 && ok[i]) st.insert(i);
    for(i=0;i<N;i++) if(bit[i]!=-1) leaf[i] = st;
    //BFS
    memset(vis,0,sizeof(vis));
    for(i=0;i<N;i++) if(bit[i]!=-1) vis[i] = 1, q.push(i);
    while(!q.empty()) {
        x = q.front(); q.pop();
        for(i=0;i<from[x].size();i++) {
            y = from[x][i];
//            printf("-- BFS %d -> %d\n",x,y);
            if(!vis[y]) {
                vis[y] = 1;
                give(y,x);
                q.push(y);
            }
        }
    }
    //Walk
    memset(vis,0,sizeof(vis));
    go(P,-1,P);
    //Answer
    ans = 0;
    for(it=p[P].begin();it!=p[P].end();it++) ans += (long long)(1LL<<bit[*it]) * val[*it];
    return ans;
}

Compilation message

Joi.cpp: In function 'void dfs(int)':
Joi.cpp:19:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from[x].size();i++) {
              ^
Joi.cpp: In function 'void give(int, int)':
Joi.cpp:27:9: warning: unused variable 'i' [-Wunused-variable]
     int i,k;
         ^
Joi.cpp: In function 'void go(int, int, int)':
Joi.cpp:38:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from[x].size();i++) if(p[P].find(from[x][i])!=p[P].end() && !vis[from[x][i]]) val[from[x][i]] = Move(from[x][i]), go(from[x][i],x,P);
              ^
Joi.cpp:38:126: error: 'Move' was not declared in this scope
     for(i=0;i<from[x].size();i++) if(p[P].find(from[x][i])!=p[P].end() && !vis[from[x][i]]) val[from[x][i]] = Move(from[x][i]), go(from[x][i],x,P);
                                                                                                                              ^
Joi.cpp:39:39: error: 'Move' was not declared in this scope
     if(last!=-1) val[last] = Move(last);
                                       ^
Joi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Joi.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from[x].size();i++) {
                  ^
Joi.cpp:42:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j,x,y,zr;
           ^

Ioi.cpp: In function 'void dfs(int)':
Ioi.cpp:19:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from[x].size();i++) {
              ^
Ioi.cpp: In function 'void give(int, int)':
Ioi.cpp:27:9: warning: unused variable 'i' [-Wunused-variable]
     int i,k;
         ^
Ioi.cpp: In function 'void go(int, int, int)':
Ioi.cpp:38:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from[x].size();i++) if(p[P].find(from[x][i])!=p[P].end() && !vis[from[x][i]]) val[from[x][i]] = Move(from[x][i]), go(from[x][i],x,P);
              ^
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from[x].size();i++) {
                  ^
Ioi.cpp:42:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j,x,y,zr;
           ^
Ioi.cpp:42:17: warning: 'zr' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int i,j,x,y,zr;
                 ^