답안 #346709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
346709 2021-01-10T19:14:23 Z ant101 항공 노선도 (JOI18_airline) C++14
컴파일 오류
0 ms 0 KB
#include "Boblib.h"
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include <complex>
#include <cassert>
#include <numeric>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define mp make_pair
#define f first
#define s second

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e2+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};


namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        // cin.exceptions(cin.failbit); // ex. throws exception when you try to read letter into int
        if (sz(s)) {
            setIn(s+".in");
            setOut(s+".out");
        } // for USACO
    }
}

using namespace io;

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);
    
    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }
    
    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);
    
    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }
    
    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }
    
    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

using namespace input;

ll add(ll a, ll b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}
ll sub(ll a, ll b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
    return a;
}

ll mul(ll a, ll b) {
    return (a * b)%MOD;
}

void add_self(ll& a, ll b) {
    a = add(a, b);
}
void sub_self(ll& a, ll b) {
    a = sub(a, b);
}
void mul_self(ll& a, ll b) {
    a = mul(a, b);
}





using namespace std ;

void Bob( int V, int U, int C[], int D[] ){
    
    if(V == 1)
    {
        InitMap(1,0) ;
        return ;
    }
    
    int cnt = 0 ;
    
    vector<int> deg( V, 0 ) ;
    vector<vector<int> > adj(V, vector<int>()) ;
    
    for(int i = 0 ; i < U ; i++ )
    {
        deg[ C[i] ]++ ;
        deg[ D[i] ]++ ;
        
        adj[ C[i] ].push_back(D[i]) ;
        adj[ D[i] ].push_back(C[i]) ;
        
    }
    
    vector<int> idx(V);
    iota(all(idx), 0);
    sort(all(idx) ,[&](int i, int j) { return deg[i] < deg[j]; }) ;
    
    vector<bool> mark(V, false) ;
    mark[ idx[V-1] ] = true ;
    
    for(auto e : adj[ idx[V-1] ])
        mark[e] = true ;
    
    int indicador ;
    for(int i = V-1 ; i >= 0 ; i-- )
        if( !mark[ idx[i] ] )
        {
            indicador = idx[i] ;
            mark[idx[i]] = true ;
            break ;
        }
    
    vector<bool> isBoring(V, false) ;
    vector<int> soma(V, 0) ;
    
    for(auto e : adj[indicador]) isBoring[e] = true , cnt++ ;
    
    //for(int i = 0 ; i < V ; i++ ) cout << idx[i] << " " << deg[idx[i]] << " " << isBoring[idx[i]] << endl ;
    
    int curLast ;
    for(int i = 0 ; i < V ; i++ )
        if(!mark[i]) curLast = i ;
    
    for(int i = 0 ; i < V ; i++ ) mark[i] = false ;
    mark[ idx[V-1] ] = true ;
    
    int curBit = V - cnt - 2 - 1 ;
    while(curLast != -1)
    {
        
        mark[curLast] = true ;
        
        int nxt = -1 ;
        
        for(auto e : adj[curLast])
        {
            if(isBoring[e])
                soma[e] += (1<<curBit) ;
            else if(!mark[e]) nxt = e ;
        }
        
        curBit--;
        curLast = nxt ;
        
    }
    
    vector< pair<int,int> > edge ;
    
    for(int i = 0 ; i < U ; i++ )
    {
        int a = C[i] ;
        int b = D[i] ;
        
        if( !isBoring[a] || !isBoring[b] ) continue ;
        
        edge.push_back( make_pair( soma[a]-1, soma[b]-1 ) ) ;
        
    }
    //cout <<"edges" << endl ;
    //for(auto e : edge ) cout << e.first << " " << e.second << endl ;
    
    InitMap(cnt, sz(edge)) ;
    for(auto e : edge ) MakeMap(e.first, e.second ) ;
    
}



    

Compilation message

Alice.cpp: In function 'void io::setIn(std::string)':
Alice.cpp:70:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   70 |     void setIn(string s) { freopen(s.c_str(),"r",stdin); }
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Alice.cpp: In function 'void io::setOut(std::string)':
Alice.cpp:71:36: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   71 |     void setOut(string s) { freopen(s.c_str(),"w",stdout); }
      |                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Alice.cpp: In function 'void Bob(int, int, int*, int*)':
Alice.cpp:236:21: warning: 'curLast' may be used uninitialized in this function [-Wmaybe-uninitialized]
  236 |         mark[curLast] = true ;
      |                     ^
Alice.cpp:221:31: warning: 'indicador' may be used uninitialized in this function [-Wmaybe-uninitialized]
  221 |     for(auto e : adj[indicador]) isBoring[e] = true , cnt++ ;
      |                               ^
/tmp/ccm9QSWr.o: In function `Bob(int, int, int*, int*)':
Alice.cpp:(.text+0x11aa): undefined reference to `InitMap(int, int)'
Alice.cpp:(.text+0x11c6): undefined reference to `MakeMap(int, int)'
Alice.cpp:(.text+0x1383): undefined reference to `InitMap(int, int)'
/tmp/ccBF9pMW.o: In function `main':
grader_alice.cpp:(.text.startup+0x108): undefined reference to `Alice(int, int, int*, int*)'
collect2: error: ld returned 1 exit status

/tmp/ccbHgQPm.o: In function `main':
grader_bob.cpp:(.text.startup+0xe8): undefined reference to `Bob(int, int, int*, int*)'
collect2: error: ld returned 1 exit status