답안 #1091937

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091937 2024-09-22T16:17:08 Z YassirSalama Designated Cities (JOI19_designated_cities) C++17
6 / 100
57 ms 604 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define F first
#define S second
const int maxn=26+10;
vector<int> v[maxn];
int mp[maxn][maxn];
bool calc[maxn][maxn];
void dfs(int node,int par){
    for(auto x:v[node]){
        if(x==par) continue;
        calc[x][node]=1;
        dfs(x,node);
    }
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    vector<pair<int,int>> ed;
    for(int i=1;i<n;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;a--,b--;
        ed.pb({a,b});
        mp[a][b]=c;
        mp[b][a]=d;
        v[a].pb(b);
        v[b].pb(a);
    }
    int dp[n+1];for(int i=0;i<=n;i++) dp[i]=1e18;
    for(int mask=0;mask<(1LL<<n);mask++){
        vector<int> r;
        for(int i=0;i<n;i++){
            if((1LL<<i)&mask) r.push_back(i);
        }
        memset(calc,0,sizeof(calc));
        for(auto x:r){
            dfs(x,x);
        }
        int ans=0;
        for(auto x:ed){
            if(!calc[x.F][x.S])
                ans+=mp[x.F][x.S];
            if(!calc[x.S][x.F]){
                ans+=mp[x.S][x.F];
            }
        }
        dp[r.size()]=min(dp[r.size()],ans);
    }
    int q;
    cin>>q;
    while(q--){
        int t;
        cin>>t;
        cout<<dp[t]<<endl;
    }


}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 50 ms 436 KB Output is correct
3 Correct 56 ms 348 KB Output is correct
4 Correct 47 ms 344 KB Output is correct
5 Correct 46 ms 348 KB Output is correct
6 Correct 48 ms 600 KB Output is correct
7 Correct 53 ms 348 KB Output is correct
8 Correct 46 ms 348 KB Output is correct
9 Correct 43 ms 348 KB Output is correct
10 Correct 57 ms 344 KB Output is correct
11 Correct 42 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 0 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 50 ms 436 KB Output is correct
3 Correct 56 ms 348 KB Output is correct
4 Correct 47 ms 344 KB Output is correct
5 Correct 46 ms 348 KB Output is correct
6 Correct 48 ms 600 KB Output is correct
7 Correct 53 ms 348 KB Output is correct
8 Correct 46 ms 348 KB Output is correct
9 Correct 43 ms 348 KB Output is correct
10 Correct 57 ms 344 KB Output is correct
11 Correct 42 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Runtime error 1 ms 604 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 0 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 50 ms 436 KB Output is correct
3 Correct 56 ms 348 KB Output is correct
4 Correct 47 ms 344 KB Output is correct
5 Correct 46 ms 348 KB Output is correct
6 Correct 48 ms 600 KB Output is correct
7 Correct 53 ms 348 KB Output is correct
8 Correct 46 ms 348 KB Output is correct
9 Correct 43 ms 348 KB Output is correct
10 Correct 57 ms 344 KB Output is correct
11 Correct 42 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Runtime error 0 ms 604 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -