답안 #834180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834180 2023-08-22T11:40:18 Z Liudas Aesthetic (NOI20_aesthetic) C++17
20 / 100
2000 ms 35236 KB
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#define int long long
using namespace std;
vector<int> path, fpath;
void DFS(int head, int par, vector<vector<pair<int, int>>> &tree){
    if(head == tree.size()-1){
        fpath = path;
        return;
    }
    for(auto[l, r] : tree[head]){
        if(l != par){
            path.push_back(r);
            DFS(l, head, tree);
            path.pop_back();
        }
    }
}
signed main(){
    int N, M;
    cin >> N >> M;
    vector<vector<pair<int, int>>> tree(N);
    vector<int> vals(M);
    for(int i = 0; i < M; i ++){
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        tree[a].push_back({b,i});
        tree[b].push_back({a,i});
        vals[i] = c;
    }
    if(M == N - 1){
        vector<int> maxsuff(N);
        for(int i = N-2; i >= 0; i --){
            maxsuff[i] = max(vals[i+1], maxsuff[i+1]);
        }
        DFS(0, -1, tree);
        int ans = 0;
        for(int i : fpath){
            ans = max(ans, maxsuff[i]);
        }
        for(int i : fpath){
            ans += vals[i];
        }
        cout << ans << endl;
    }
    else{
        int an = 0;
        for(int i = 0; i < M-1; i ++){
            int tval = *max_element(vals.begin()+i+1, vals.end());
            vals[i] += tval;
            priority_queue<vector<int>> que;
            que.push({0,0});
            int ans = 0;
            vector<bool> vis(N);
            while(!que.empty()){
                int a = -que.top()[0], b = que.top()[1];
                que.pop();
                if(b == N-1){ans = a; break;}
                if(vis[b])continue;
                vis[b] = true;
                for(auto [l, r] : tree[b]){
                    que.push({-a-vals[r], l});
                }
            }
            an = max(an, ans);
            vals[i] -= tval;
        }
        cout << an << endl;
    }
    return 0;
}

Compilation message

Aesthetic.cpp: In function 'void DFS(long long int, long long int, std::vector<std::vector<std::pair<long long int, long long int> > >&)':
Aesthetic.cpp:10:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     if(head == tree.size()-1){
      |        ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1029 ms 520 KB Output is correct
10 Correct 940 ms 516 KB Output is correct
11 Correct 862 ms 444 KB Output is correct
12 Correct 847 ms 448 KB Output is correct
13 Correct 890 ms 468 KB Output is correct
14 Correct 923 ms 464 KB Output is correct
15 Correct 928 ms 468 KB Output is correct
16 Correct 940 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 28024 KB Output is correct
2 Correct 344 ms 28356 KB Output is correct
3 Correct 350 ms 27948 KB Output is correct
4 Correct 330 ms 27936 KB Output is correct
5 Correct 350 ms 27980 KB Output is correct
6 Correct 352 ms 28780 KB Output is correct
7 Correct 335 ms 28612 KB Output is correct
8 Correct 359 ms 28588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2075 ms 26056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2075 ms 35236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2075 ms 35236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1029 ms 520 KB Output is correct
10 Correct 940 ms 516 KB Output is correct
11 Correct 862 ms 444 KB Output is correct
12 Correct 847 ms 448 KB Output is correct
13 Correct 890 ms 468 KB Output is correct
14 Correct 923 ms 464 KB Output is correct
15 Correct 928 ms 468 KB Output is correct
16 Correct 940 ms 468 KB Output is correct
17 Correct 349 ms 28024 KB Output is correct
18 Correct 344 ms 28356 KB Output is correct
19 Correct 350 ms 27948 KB Output is correct
20 Correct 330 ms 27936 KB Output is correct
21 Correct 350 ms 27980 KB Output is correct
22 Correct 352 ms 28780 KB Output is correct
23 Correct 335 ms 28612 KB Output is correct
24 Correct 359 ms 28588 KB Output is correct
25 Execution timed out 2075 ms 26056 KB Time limit exceeded
26 Halted 0 ms 0 KB -