답안 #262622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262622 2020-08-13T05:46:04 Z 반딧불(#5089) Pairs (IOI07_pairs) C++17
0 / 100
44 ms 3212 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

pairs.cpp: In function 'int main()':
pairs.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);
      |     ~~~~~^~~~~~~~~~~~~~~~~
pairs.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);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp: In function 'void renumber()':
pairs.cpp:24:9: warning: 'stP' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     int stP;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 2040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 44 ms 3180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 43 ms 3156 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 3116 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 3180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 41 ms 3180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 3060 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 3188 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 36 ms 3212 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -