Submission #442029

#TimeUsernameProblemLanguageResultExecution timeMemory
442029JovanBRestore Array (RMI19_restore)C++17
7 / 100
648 ms568 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MAXN = 5000; int dist[MAXN+5]; const int INF = 1000000; int ea[4*MAXN+5]; int eb[4*MAXN+5]; int ec[4*MAXN+5]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; vector <tuple <int, int, int>> edges; for(int i=1; i<=m; i++){ int l, r, k, val; cin >> l >> r >> k >> val; l++; r++; if(val == 1){ ea[i] = l-1; eb[i] = r; ec[i] = k-1; } else{ ea[i] = r; eb[i] = l-1; ec[i] = -k; } } for(int i=1; i<=n; i++){ m++; ea[m] = i-1; eb[m] = i; ec[m] = 1; m++; ea[m] = i; eb[m] = i-1; ec[m] = 0; } for(int i=1; i<=n; i++) dist[i] = INF; for(int k=0; k<n; k++){ for(int j=1; j<=m; j++){ int a = ea[j]; int b = eb[j]; int c = ec[j]; if(dist[a] != INF && dist[b] > dist[a] + c) dist[b] = dist[a] + c; } } for(int j=1; j<=m; j++){ int a = ea[j]; int b = eb[j]; int c = ec[j]; if(dist[a] != INF && dist[b] > dist[a] + c){ cout << "-1\n"; return 0; } } for(int i=1; i<=n; i++){ cout << (1^(dist[i] - dist[i-1])) << " "; } cout << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...