답안 #338435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338435 2020-12-23T06:09:24 Z beksultan04 바이오칩 (IZhO12_biochips) C++14
0 / 100
7 ms 9708 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 2e5+11,INF=1e9+7;
int n,m,tin[N],tout[N],cnt,ves[N],cot;
vector <int> gg[N],g[N];
void rec(int x,int p){
    tin[x]=++cnt;
    int i;
    for (i=0;i<gg[x].size();++i){
        if (gg[x][i] != p)
            rec(gg[x][i],x);
    }
    tout[x]=++cnt;
}

bool is_predok(int a,int b){
    bool f = (tin[a] <= tin[b] && tout[a] >= tout[b]);
    swap(a,b);
    f |= (tin[a] <= tin[b] && tout[a] >= tout[b]);
    ret f;
}
set <int> s;
vector <int> v;
map <pii,bool>mp;
void dfs(int x,int p,int cnt,int sum){
    if (cnt == m){
        cot = max(cot,sum);
        ret ;
    }
    int i;
    for (i=0;i<g[x].size();++i){
        bool f=0;
        for (int j=0;j<v.size();++j){
            if (mp[{v[j],g[x][i]}] == 1)f=1;
        }
        if (g[x][i]==p || f)continue;
        v.pb(g[x][i]);
        dfs(g[x][i],x,cnt+1,sum+ves[g[x][i]]);
        v.pop_back();
    }
}


main(){
    int i,j,s,cnt=1;
    scan2(n,m)
    for (i=1;i<=n;++i){
        int x;
        scan2(x,ves[i])
        if (x == 0)s=i;
        else {
            gg[x].pb(i);
            gg[i].pb(x);
        }
    }
    rec(s,0);
    for (i=1;i<=n;++i){
        for (j=i+1;j<=n;++j){
            if (!is_predok(i,j)){
                g[i].pb(j);
                g[j].pb(i);
            }
            else {
                mp[{i,j}] = 1;
                mp[{j,i}] = 1;
            }
        }
    }
    for (i=1;i<=n;++i){
        v.pb(i);
        dfs(i,0,1,ves[i]);
        v.pop_back();
    }
    cout <<cot;
    ret 0;

}

Compilation message

biochips.cpp: In function 'void rec(long long int, long long int)':
biochips.cpp:25:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (i=0;i<gg[x].size();++i){
      |              ~^~~~~~~~~~~~~
biochips.cpp: In function 'void dfs(long long int, long long int, long long int, long long int)':
biochips.cpp:47:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
biochips.cpp:49:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int j=0;j<v.size();++j){
      |                      ~^~~~~~~~~
biochips.cpp: At global scope:
biochips.cpp:60:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main(){
      |      ^
biochips.cpp: In function 'int main()':
biochips.cpp:61:15: warning: unused variable 'cnt' [-Wunused-variable]
   61 |     int i,j,s,cnt=1;
      |               ^~~
biochips.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
biochips.cpp:62:5: note: in expansion of macro 'scan2'
   62 |     scan2(n,m)
      |     ^~~~~
biochips.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
biochips.cpp:65:9: note: in expansion of macro 'scan2'
   65 |         scan2(x,ves[i])
      |         ^~~~~
biochips.cpp:72:8: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |     rec(s,0);
      |     ~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 9708 KB Output isn't correct
2 Halted 0 ms 0 KB -