Submission #1020250

#TimeUsernameProblemLanguageResultExecution timeMemory
1020250MrPavlitoMonthly railway pass (LMIO18_menesinis_bilietas)C++17
100 / 100
1265 ms186660 KiB
#include <bits/stdc++.h> //#define int long long #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define sc second #define endl "\n" #define pii pair<int,int> using namespace std; const int MAXN = 5e5+5; const int mod7 = 1e9+7; const long long inf = 1e18; int n,m; struct grana{int a,b;string c;}; vector<vector<pii>> graf(MAXN); vector<unordered_set<int>> compressGraf(MAXN); int whichCMP[MAXN]; bool visited[MAXN]; void dfs(int nod, int cmp) { visited[nod] = 1; whichCMP[nod] = cmp; for(auto x: graf[nod]) { if(x.sc == 1)continue; if(!visited[x.fi])dfs(x.fi,cmp); } } signed main() { ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0); int tt=1; //cin >> tt; while(tt--) { cin >> n >> m; vector<grana> svegrane; map<pii, string> mapa; for(int i=0; i<m; i++) { int a,b;string c; cin >> a >> b >> c; if(a>b)swap(a,b); svegrane.pb({a,b,c}); if(mapa[mp(a,b)] == "T")continue; mapa[mp(a,b)] = c; } //for(auto x: mapa)cout << x.fi.fi << " " << x.fi.sc << ":" << x.sc << endl; for(auto x: svegrane) { int a = x.a; int b = x.b; string c = x.c; if(c == "A" && mapa[mp(a,b)] == "T")continue; if(c=="T") { graf[a].pb(mp(b,0)); graf[b].pb(mp(a,0)); } else { graf[a].pb(mp(b,1)); graf[b].pb(mp(a,1)); } //svegrane.pb({a,b,c}); } int c = 0; for(int i=1; i<=n; i++) { if(!visited[i]) { c++; dfs(i,c); } } //for(int i=1; i<=n; i++)cout << i << " " << whichCMP[i] << endl; for(auto x: svegrane) { if(x.c == "A" && mapa[mp(x.a,x.b)] == "T")continue; if(x.c == "T")continue; if(whichCMP[x.a] == whichCMP[x.b])continue; compressGraf[whichCMP[x.a]].insert(whichCMP[x.b]); compressGraf[whichCMP[x.b]].insert(whichCMP[x.a]); } int rez = 0; for(int i=1; i<=n; i++) { if(compressGraf[whichCMP[i]].size() == c-1)rez++; } cout << rez << endl; } } /* 7 9 7 5 A 3 7 A 3 1 A 3 4 T 3 5 A 7 1 A 5 6 T 2 7 T 6 5 A */

Compilation message (stderr)

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:96:49: warning: comparison of integer expressions of different signedness: 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   96 |             if(compressGraf[whichCMP[i]].size() == c-1)rez++;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
#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...