제출 #642669

#제출 시각아이디문제언어결과실행 시간메모리
642669joshjmsMonthly railway pass (LMIO18_menesinis_bilietas)C++14
16 / 100
219 ms53768 KiB
#include <bits/stdc++.h> using namespace std; #define ld long double #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << "\n" const int mod = 998244353; const ld E = 1e-4; struct Edge { int u, v; char c; } a[500005]; int n, m, sum; vector <int> g[500005]; int par[500005], sz[500005]; vector <int> e[500005]; int find(int u) { if(u == par[u]) return u; return par[u] = find(par[u]); } int join(int u, int v) { u = find(u); v = find(v); if(u == v) return 0; if(e[u].size() > e[v].size()) { par[v] = u; sz[u] += sz[v]; for(auto i : e[v]) e[u].pb(i); } else { par[u] = v; sz[v] += sz[u]; for(auto i : e[u]) e[v].pb(i); } return 1; } int ans[500005]; void solve () { cin >> n >> m; for(int i = 1; i <= n; i++) { par[i] = i; sz[i] = 1; ans[i] = -1; } for(int i = 1; i <= m; i++) { cin >> a[i].u >> a[i].v >> a[i].c; } for(int i = 1; i <= m; i++) { if(a[i].c == 'A') { e[a[i].u].pb(a[i].v); e[a[i].v].pb(a[i].u); } } for(int i = 1; i <= m; i++) { if(a[i].c == 'T') { join(a[i].u, a[i].v); } } for(int i = 1; i <= n; i++) { for(int j = 0; j < e[i].size(); j++) e[i][j] = find(e[i][j]); sort(e[i].begin(), e[i].end()); e[i].resize(unique(e[i].begin(), e[i].end()) - e[i].begin()); } for(int i = 1; i <= n; i++) { int u = find(i); if(ans[u] == -1) { int s = sz[u]; for(auto j : e[u]) { s += sz[find(j)]; } if(s == n) ans[u] = 1; else ans[u] = 0; } sum += ans[u]; } cout << sum << "\n"; } signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve (); }

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

menesinis_bilietas.cpp: In function 'void solve()':
menesinis_bilietas.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int j = 0; j < e[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~
#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...