Submission #682117

#TimeUsernameProblemLanguageResultExecution timeMemory
682117as111Traffic (CEOI11_tra)C++14
0 / 100
247 ms23532 KiB
#include <iostream> #include <vector> #include <stack> #include <set> #include <map> #define MAXN 100000 using namespace std; int N, M; set<pair<int, int>> west; set<int> east; vector<int> adj[MAXN + 1]; vector<int> rev[MAXN + 1]; stack<int> S; bool visited[MAXN + 1]; int ID[MAXN + 1]; vector<int> components[MAXN]; int numComponents; int ans[MAXN + 1]; void dfs1(int x) { visited[x] = true; for (int i = 0; i < adj[x].size(); i++) { if (!visited[adj[x][i]]) dfs1(adj[x][i]); } S.push(x); } void dfs2(int x) { ID[x] = numComponents; components[numComponents].push_back(x); visited[x] = true; if (east.count(x)) ans[ID[x]]++; for (int i = 0; i < rev[x].size(); i++) { if (!visited[rev[x][i]]) dfs2(rev[x][i]); } } int main() { int A, B; cin >> N >> M >> A >> B; for (int i = 0; i < N; i++) { int x, y; cin >> x >> y; if (x == 0) { west.insert({ -y,i });//dec y coords } if (x == A) { east.insert(i); } } for (int m = 0; m < M; m++) { int a, b, k; cin >> a >> b >> k; adj[a].push_back(b); rev[b].push_back(a); if (k != 1) { adj[b].push_back(a); rev[a].push_back(b); } } for (int i = 0; i < N; i++) { if (!visited[i]) dfs1(i); } for (int i = 0; i < N; i++) { visited[i] = false; } while (!S.empty()) { int v = S.top(); S.pop(); if (!visited[v]) { dfs2(v); numComponents++; } } for (auto e : west) { cout << ans[ID[e.second]] << endl; } }

Compilation message (stderr)

tra.cpp: In function 'void dfs1(int)':
tra.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (int i = 0; i < adj[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~
tra.cpp: In function 'void dfs2(int)':
tra.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for (int i = 0; i < rev[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~
#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...
#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...