답안 #272685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
272685 2020-08-18T13:32:01 Z eohomegrownapps Restore Array (RMI19_restore) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,m;
int INF = 1e9;

void relaxedges(){
    vector<vector<pair<int,int>>> adjlist(n+1); //node,val
    for (int i = 0; i<m; i++){
        int l,r,k,v;
        cin>>l>>r>>k>>v;
        r++;
        if (v==0){
            //a[i]=l;
            //b[i]=r;
            //c[i]=k-(r-l);
            adjlist[r].push_back({l,r-l-k});
        } else {
            //a[i]=r;
            //b[i]=l;
            //c[i]=(r-l)-k+1;
            adjlist[l].push_back({r,k-1-(r-l)});
        }
    }
    for (int i = 0; i<n; i++){
        //a[m+2*i]=i;
        //b[m+2*i]=i+1;
        //c[m+2*i]=-1;
        adjlist[i+1].push_back({i,1});
        //a[m+2*i+1]=i+1;
        //b[m+2*i+1]=i;
        //c[m+2*i+1]=0;
        adjlist[i].push_back({i+1,0});
    }
    m+=2*n;
    bool works = true;
    vector<int> distances(n+1,INF);
    distances[0]=0;
    inqueue[0]=true;
    vector<int> numpaths(n+1,0);
    vector<bool> inqueue(n+1,false);
    queue<int> q;
    q.push(0);
    while (q.size()>0&&works){
        int f = q.front();
        q.pop();
        inqueue[f]=false;
        for (auto p : adjlist[f]){
            if (distances[p.first]>distances[f]+p.second){
                distances[p.first]=distances[f]+p.second;
                numpaths[p.first]=numpaths[f]+1;
                if (numpaths[p.first]>=n+1){
                    works=false;
                    break;
                }
                if (!inqueue[p.first]){
                    q.push(p.first);
                    inqueue[p.first]=true;
                }
            }
        }
    }
    if (!works){
        cout<<-1<<'\n';
        return;
    }

    /*for (int i = 0; i<=n; i++){
        cout<<distances[i]<<' ';
    }cout<<'\n';*/
    for (int i = 0; i<n; i++){
        cout<<-(distances[i+1]-distances[i])<<' ';
    }cout<<'\n';
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    /*if (n<=18){
        subtask1();
    } else {*/
        relaxedges();
    //}
}

Compilation message

restore.cpp: In function 'void relaxedges()':
restore.cpp:40:5: error: 'inqueue' was not declared in this scope; did you mean 'sigqueue'?
   40 |     inqueue[0]=true;
      |     ^~~~~~~
      |     sigqueue