답안 #27128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27128 2017-07-09T12:59:57 Z top34051 Amusement Park (JOI17_amusement_park) C++14
0 / 100
172 ms 68212 KB
#include "Joi.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]] && 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(k);
    leaf[x].erase(k); leaf[x].insert(k);
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
    int i,j,x,y;
    for(i=0;i<M;i++) from[A[i]].push_back(B[i]), from[B[i]].push_back(A[i]);
    //Build graph
    dfs(0);
    //All nodes
    st.clear();
    for(i=0;i<N;i++) if(bit[i]) st.insert(i);
    for(i=0;i<N;i++) if(bit[i]) p[i] = st;
    //All leaves
    st.clear();
    for(i=0;i<N;i++) if(bit[i] && ok[i]) st.insert(i);
    for(i=0;i<N;i++) if(bit[i]) leaf[i] = st;
    //BFS
    for(i=0;i<N;i++) if(bit[i]) 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];
            if(!vis[y]) {
                vis[y] = 1;
                give(y,x);
                q.push(y);
            }
        }
    }
    //Assign
    for(i=1;i<=60;i++) val[i] = X&1, X/=2;
    for(i=0;i<N;i++) MessageBoard(i, val[bit[i]]);
}
#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]] && 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(k);
    leaf[x].erase(k); leaf[x].insert(k);
}
void go(int x,int last,int P) {
    int i;
    for(i=0;i<from[x].size();i++) if(p[P].find(from[x][i])!=p[P].end()) 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;
    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]);
    //Build graph
    dfs(0);
    //All nodes
    st.clear();
    for(i=0;i<N;i++) if(bit[i]) st.insert(i);
    for(i=0;i<N;i++) if(bit[i]) p[i] = st;
    //All leaves
    st.clear();
    for(i=0;i<N;i++) if(bit[i] && ok[i]) st.insert(i);
    for(i=0;i<N;i++) if(bit[i]) leaf[i] = st;
    //BFS
    for(i=0;i<N;i++) if(bit[i]) 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];
            if(!vis[y]) {
                vis[y] = 1;
                give(y,x);
                q.push(y);
            }
        }
    }
    //Walk
    go(P,-1,P);
    //Answer
    ans = 0;
    for(it=p[P].begin();it!=p[P].end();it++) ans += (1<<(*it-1)) * 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 Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:52:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from[x].size();i++) {
                  ^
Joi.cpp:36:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j,x,y;
           ^

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:37: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()) 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:59:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from[x].size();i++) {
                  ^
Ioi.cpp:41:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j,x,y;
           ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 9512 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 149 ms 64252 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 9508 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 149 ms 68212 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 172 ms 65308 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -