답안 #27148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27148 2017-07-09T14:51:23 Z top34051 Amusement Park (JOI17_amusement_park) C++14
0 / 100
196 ms 69008 KB
#include "Joi.h"
#include<bits/stdc++.h>
using namespace std;
int cnt1;
int bit1[10005];
int val1[65];
bool vis1[10005];
bool ok1[10005];
vector<int> from1[10005];
set<int> st1;
set<int> p1[10005];
set<int> leaf1[10005];
queue<int> q1;
void dfs1(int x) {
    int i;
    if(cnt1>=60) return ;
    ok1[x] = 1;
    bit1[x] = cnt1++;
    for(i=0;i<from1[x].size();i++) {
        if(bit1[from1[x][i]]==-1 && cnt1<60) {
            ok1[x] = 0;
            dfs1(from1[x][i]);
        }
    }
}
void give1(int x,int y) {
//    printf("GIVE %d <= %d\n",x,y);
    int i,k;
    set<int>::iterator it;
    for(it=leaf1[y].begin();it!=leaf1[y].end();it++) if(*it!=y) k = *it;
    bit1[x] = bit1[k];
    p1[x] = p1[y]; leaf1[x] = leaf1[y];
    p1[x].erase(k); p1[x].insert(x);
    leaf1[x].erase(k); leaf1[x].insert(x);
}
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++) from1[A[i]].push_back(B[i]), from1[B[i]].push_back(A[i]);
    //Build graph
    memset(bit1,-1,sizeof(bit1));
    dfs1(0);
    if(from1[0].size()==1) ok1[0] = 1;
    //All nodes
    st1.clear();
    for(i=0;i<N;i++) if(bit1[i]!=-1) st1.insert(i);
    for(i=0;i<N;i++) if(bit1[i]!=-1) p1[i] = st1;
    //All leaves
    st1.clear();
    for(i=0;i<N;i++) if(bit1[i]!=-1 && ok1[i]) st1.insert(i);
    for(i=0;i<N;i++) if(bit1[i]!=-1) leaf1[i] = st1;

//    for(i=0;i<N;i++) for(set<int>::iterator it=leaf1[i].begin();it!=leaf1[i].end();++it) printf("%d -> %d\n",i,*it);

    //BFS
    for(i=0;i<N;i++) if(bit1[i]!=-1) vis1[i] = 1, q1.push(i);
    while(!q1.empty()) {
        x = q1.front(); q1.pop();
        for(i=0;i<from1[x].size();i++) {
            y = from1[x][i];
            if(!vis1[y]) {
                vis1[y] = 1;
                give1(y,x);
                q1.push(y);
            }
        }
    }
    //Assign
    for(i=0;i<60;i++) val1[i] = X&1, X/=2;
    for(i=0;i<N;i++) MessageBoard(i, val1[bit1[i]]);
//    printf("END JOI\n");
}
#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;
    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
    memset(bit,-1,sizeof(bit));
    dfs(0);
    if(from[0].size()==1) ok[0] = 1;
    //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
    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];
            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 dfs1(int)':
Joi.cpp:19:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from1[x].size();i++) {
              ^
Joi.cpp: In function 'void give1(int, int)':
Joi.cpp:28: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:58:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from1[x].size();i++) {
                  ^
Joi.cpp:37: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: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:62: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;
           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7760 KB Output is correct
2 Incorrect 3 ms 8552 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 159 ms 67160 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7760 KB Output is correct
2 Correct 0 ms 7760 KB Output is correct
3 Incorrect 0 ms 7760 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 196 ms 69008 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 149 ms 66104 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -