제출 #67783

#제출 시각아이디문제언어결과실행 시간메모리
67783aquablitz11장난감 기차 (IOI17_train)C++14
12 / 100
356 ms2576 KiB
#include <bits/stdc++.h> #include "train.h" using namespace std; const int N = 5e3+10; vector<int> G[N], R[N]; vector<int> who_wins(vector<int> A, vector<int> C, vector<int> U, vector<int> V) { // input int n = A.size(); int m = U.size(); for (int i = 0; i < m; ++i) { G[U[i]].push_back(V[i]); R[V[i]].push_back(U[i]); } vector<int> ans(n, 0); for (int i = 0; i < n; ++i) if (C[i]) { // i = main recharger we need for cycle // first step: find all nodes that can be forced to reach i vector<bool> reach(n, false); vector<int> cnt(n, 0); queue<int> Q; Q.push(i); reach[i] = true; while (!Q.empty()) { int u = Q.front(); Q.pop(); for (auto p : R[u]) if (!reach[p]) { ++cnt[p]; if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size())) { reach[p] = true; Q.push(p); } } } // second step: find if i could be in cycle or not int cntr = 0; for (auto v : G[i]) if (reach[v]) ++cntr; if ((A[i] && cntr > 0) || (!A[i] && cntr == G[i].size())) { // third step: add all nodes that could reach the cycle to answer for (int i = 0; i < n; ++i) if (reach[i]) ans[i] += 1; } } vector<int> cnt(n, 0); queue<int> Q; for (int u = 0; u < n; ++u) if (ans[u]) Q.push(u); while (!Q.empty()) { int u = Q.front(); Q.pop(); for (auto p : R[u]) if (!ans[p]) { ++cnt[p]; if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size())) { ans[p] = true; Q.push(p); } } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:30:63: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size())) {
train.cpp:39:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if ((A[i] && cntr > 0) || (!A[i] && cntr == G[i].size())) {
                                             ~~~~~^~~~~~~~~~~~~~
train.cpp:53:59: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size())) {
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...