We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
링크
#include <algorithm> #include <iostream> #include <string> #include <vector> #include <queue> using namespace std; void solution() { int N; cin >> N; vector<int> answers(N + 1, 0); vector<int> costs(N + 1); vector<vector<int> > graph(N + 1); vector<int> indegree(N + 1, 0); for (int i = 1; i <= N; i++) { int time, cur = 0; cin >> time; costs[i] = time; while (cin >> cur, cur!=-1) { graph[cur].push_back(i); indegree[i] += 1; } } queue<int> q; // find the roots for (int i = 1; i <= N; i++) { if (indegree[i] == 0) { q.push(i); answers[i] = costs[i]; } } while (!q.empty()) { int cur = q.front(); q.pop(); for (int next : graph[cur]) { answers[next] = max(answers[next], answers[cur] + costs[next]); indegree[next] -= 1; if (indegree[next] == 0) q.push(next); } } for (int i = 1; i < answers.size();i++) { cout << answers[i] << "\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solution(); return 0; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
문제번호. 문제 제목
링크
설계
위상정렬
정리
고생한 점
code
The text was updated successfully, but these errors were encountered: