Skip to content

Commit

Permalink
Merge pull request #130 from hyxrxn/main
Browse files Browse the repository at this point in the history
week17_hyxrxn
  • Loading branch information
hjk0761 authored Sep 9, 2024
2 parents e0d44e5 + a4f6b7a commit aaa3f19
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
40 changes: 40 additions & 0 deletions week17/B_31997/hyxrxn/31997.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <algorithm>
using namespace std;

int n, m, t;
int arrive[202020];
int leave[202020];
long long st[202020];
long long et[202020];

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);

cin >> n >> m >> t;
for (int i = 1; i <= n; i++) {
cin >> arrive[i] >> leave[i];
}

int c, d, s, e;
for (int i = 0; i < m; i++) {
cin >> c >> d;
s = max(arrive[c], arrive[d]);
e = min(leave[c], leave[d]);
if (s < e) {
st[s]++;
et[e]++;
}
}

cout << st[0] - et[0] << "\n";
for (int i = 1; i < t; i++) {
st[i] += st[i - 1];
et[i] += et[i - 1];
cout << st[i] - et[i] << "\n";
}

return 0;
}
65 changes: 65 additions & 0 deletions week17/C_31932/hyxrxn/31932.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <iostream>
#include <vector>
#include <tuple>
#include <queue>
#include <algorithm>
using namespace std;

// 도착지점을 갈 수 있는 빙하 탐색하며 그 빙하에 도달할 수 있는 최댓값 갱신
// 반복하며 시작 지점의 도달 최댓값 갱신
// 도달 최댓값이 먹을 수 있는 연어의 최대 수일듯...

int n, m;
vector<vector<tuple<int, int, int>>> vec(101010);
priority_queue<pair<int, int>> pq;
int visit[101010] = {0};
int until[101010] = {0};

int main() {
cin >> n >> m;

int u, v, d, t;
for (int i = 0; i < m; i++) {
cin >> u >> v >> d >> t;
vec[u].push_back({v, d, t});
vec[v].push_back({u, d, t});
}

until[1] = -1;
visit[n] = 1;
for (const auto &item: vec[n]) {
int next = get<0>(item);
int dis = get<1>(item);
int tim = get<2>(item);

if (tim - dis >= 0) {
until[next] = max(until[next], tim - dis);
pq.push({until[next], next});
}
}

while (!pq.empty()) {
pair<int, int> a = pq.top();
pq.pop();
int pre = a.second;
int now = a.first;
visit[pre] = 1;

for (const auto &item: vec[pre]) {
int next = get<0>(item);
int dis = get<1>(item);
int tim = get<2>(item);

if (visit[next] == 0 && now <= tim) {
until[next] = max(until[next], now - dis);
pq.push({until[next], next});
}
}
}

cout << until[1];

return 0;
}

// 18에서 런타임에러

0 comments on commit aaa3f19

Please sign in to comment.