제출 #198450

#제출 시각아이디문제언어결과실행 시간메모리
198450oolimryMonthly railway pass (LMIO18_menesinis_bilietas)C++14
16 / 100
558 ms75180 KiB
#include <bits/stdc++.h> using namespace std; static int p[500005]; int numSets; int findSet(int u){ if(p[u] == u) return u; else{ p[u] = findSet(p[u]); return p[u]; } } void unionSet(int u, int v){ u = findSet(u); v = findSet(v); if(u == v) return; p[u] = v; numSets--; } typedef pair<int,int> ii; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; numSets = n; unordered_set<int> edges[n]; for(int i = 0;i < n;i++) p[i] = i; vector<ii> bus; for(int i = 0;i < m;i++){ int u, v; char c; cin >> u >> v >> c; u--; v--; if(c == 'T'){ unionSet(u,v); } else{ bus.push_back(ii(u,v)); } } for(ii e : bus){ int u = findSet(e.first); int v = findSet(e.second); edges[u].insert(v); edges[v].insert(u); } int ans = 0; for(int i = 0;i < n;i++){ if(numSets - 1 == edges[findSet(i)].size()) ans++; } cout << ans << "\n"; }

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

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:52:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(numSets - 1 == edges[findSet(i)].size()) ans++;
      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...