Submission #262613

# Submission time Handle Problem Language Result Execution time Memory
262613 2020-08-13T05:19:56 Z 반딧불(#5089) Training (IOI07_training) C++17
30 / 100
3 ms 512 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct dat{
    int x, y, c;
    dat(){}
    dat(int x, int y, int c): x(x), y(y), c(c){}
    bool operator<(const dat &r)const{
        return y<r.y;
    }
};

int n, m;
int ans;
vector<int> treeLink[1002];
vector<dat> vec;
int idx[1002];
int DP[1002];

void renumber(){
    int stP;
    for(int i=1; i<=n; i++){
        if((int)treeLink[i].size() == 1){
            idx[i] = 1, stP = i;
            break;
        }
    }

    int prv = 0;
    for(int i=2; i<=n; i++){
        for(auto &x: treeLink[stP]){
            if(x == prv) continue;
            prv = stP;
            stP = x;
            idx[x] = i;
            break;
        }
    }

    for(int i=0; i<(int)vec.size(); i++){
        vec[i].x = idx[vec[i].x];
        vec[i].y = idx[vec[i].y];
        if(vec[i].x > vec[i].y) swap(vec[i].x, vec[i].y);
    }
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=m; i++){
        int u, v, c;
        scanf("%d %d %d", &u, &v, &c);
        if(c == 0){
            treeLink[u].push_back(v);
            treeLink[v].push_back(u);
        }
        else{
            vec.push_back(dat(u, v, c));
            ans += c;
        }
    }

    renumber();
    sort(vec.begin(), vec.end());
    int pnt = 0;
    for(int i=1; i<=n; i++){
        DP[i] = DP[i-1];
        while(pnt < (int)vec.size() && vec[pnt].y <= i){
            if((vec[pnt].y - vec[pnt].x) % 2 == 1){
                pnt++;
                continue;
            }

            DP[i] = max(DP[i], DP[vec[pnt].x] + vec[pnt].c);
            pnt++;
        }
    }

    printf("%d", ans - DP[n]);
}

Compilation message

training.cpp: In function 'int main()':
training.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
training.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |         scanf("%d %d %d", &u, &v, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
training.cpp: In function 'void renumber()':
training.cpp:24:9: warning: 'stP' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     int stP;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -