Submission #219460

# Submission time Handle Problem Language Result Execution time Memory
219460 2020-04-05T11:06:37 Z quocnguyen1012 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
413 ms 49504 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 5e5 + 5;

vector<int> adj[maxn], train[maxn];
int comp[maxn], cc = 0;
vector<ii> bus;
int N, M;
bool vis[maxn];

void dfs(int u)
{
  vis[u] = true;
  comp[u] = cc;
  for(int v : train[u]) if(!vis[v]){
    dfs(v);
  }
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> M;
  while(M--){
    int u, v; cin >> u >> v;
    char type; cin >> type;
    if(type == 'T'){
      train[u].pb(v);
      train[v].pb(u);
    }
    else{
      bus.eb(u, v);
    }
  }
  for(int i = 1; i <= N; ++i){
    if(!vis[i]){
      ++cc;
      dfs(i);
    }
  }
  for(auto & all : bus){
    int u = comp[all.fi];
    int v = comp[all.se];
    if(u == v) continue;
    adj[u].eb(v); adj[v].eb(u);
  }
  for(int i = 1; i <= cc; ++i){
    sort(adj[i].begin(), adj[i].end());
    adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end());
  }
  int res = 0;
  for(int i = 1; i <= N; ++i){
    if(adj[comp[i]].size() == cc - 1) ++res;
  }
  cout << res;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:67:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(adj[comp[i]].size() == cc - 1) ++res;
        ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 413 ms 47352 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 19 ms 23936 KB Output is correct
4 Correct 24 ms 26112 KB Output is correct
5 Correct 19 ms 23936 KB Output is correct
6 Correct 71 ms 28920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 26112 KB Output is correct
2 Correct 20 ms 23808 KB Output is correct
3 Correct 20 ms 23808 KB Output is correct
4 Correct 24 ms 24064 KB Output is correct
5 Correct 19 ms 23936 KB Output is correct
6 Correct 160 ms 35040 KB Output is correct
7 Correct 290 ms 49504 KB Output is correct
8 Correct 25 ms 24704 KB Output is correct
9 Correct 30 ms 25080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 20 ms 23908 KB Output is correct
4 Correct 20 ms 23936 KB Output is correct
5 Correct 21 ms 24064 KB Output is correct
6 Correct 20 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 22 ms 24192 KB Output is correct
10 Correct 19 ms 23808 KB Output is correct
11 Correct 20 ms 23936 KB Output is correct
12 Correct 19 ms 23808 KB Output is correct
13 Correct 19 ms 23936 KB Output is correct
14 Correct 19 ms 23936 KB Output is correct
15 Correct 20 ms 23936 KB Output is correct
16 Correct 19 ms 23808 KB Output is correct
17 Correct 19 ms 23936 KB Output is correct
18 Correct 20 ms 23808 KB Output is correct
19 Correct 20 ms 23808 KB Output is correct
20 Correct 24 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 20 ms 23908 KB Output is correct
4 Correct 20 ms 23936 KB Output is correct
5 Correct 21 ms 24064 KB Output is correct
6 Correct 20 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 22 ms 24192 KB Output is correct
10 Correct 19 ms 23808 KB Output is correct
11 Correct 20 ms 23936 KB Output is correct
12 Correct 19 ms 23808 KB Output is correct
13 Correct 19 ms 23936 KB Output is correct
14 Correct 19 ms 23936 KB Output is correct
15 Correct 20 ms 23936 KB Output is correct
16 Correct 27 ms 24728 KB Output is correct
17 Correct 134 ms 35500 KB Output is correct
18 Correct 63 ms 28352 KB Output is correct
19 Correct 78 ms 29932 KB Output is correct
20 Correct 54 ms 27380 KB Output is correct
21 Correct 80 ms 29288 KB Output is correct
22 Correct 19 ms 23808 KB Output is correct
23 Correct 19 ms 23936 KB Output is correct
24 Correct 20 ms 23808 KB Output is correct
25 Correct 20 ms 23808 KB Output is correct
26 Correct 24 ms 24064 KB Output is correct
27 Correct 19 ms 23936 KB Output is correct
28 Correct 25 ms 24704 KB Output is correct
29 Correct 30 ms 25080 KB Output is correct
30 Correct 71 ms 28920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 20 ms 23908 KB Output is correct
4 Correct 20 ms 23936 KB Output is correct
5 Correct 21 ms 24064 KB Output is correct
6 Correct 20 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 22 ms 24192 KB Output is correct
10 Correct 19 ms 23808 KB Output is correct
11 Correct 20 ms 23936 KB Output is correct
12 Correct 19 ms 23808 KB Output is correct
13 Correct 19 ms 23936 KB Output is correct
14 Correct 19 ms 23936 KB Output is correct
15 Correct 20 ms 23936 KB Output is correct
16 Correct 27 ms 24728 KB Output is correct
17 Correct 134 ms 35500 KB Output is correct
18 Correct 63 ms 28352 KB Output is correct
19 Correct 78 ms 29932 KB Output is correct
20 Correct 54 ms 27380 KB Output is correct
21 Correct 80 ms 29288 KB Output is correct
22 Correct 413 ms 47352 KB Output is correct
23 Correct 19 ms 23808 KB Output is correct
24 Correct 19 ms 23936 KB Output is correct
25 Correct 24 ms 26112 KB Output is correct
26 Correct 20 ms 23808 KB Output is correct
27 Correct 20 ms 23808 KB Output is correct
28 Correct 24 ms 24064 KB Output is correct
29 Correct 19 ms 23936 KB Output is correct
30 Correct 160 ms 35040 KB Output is correct
31 Correct 290 ms 49504 KB Output is correct
32 Correct 46 ms 26352 KB Output is correct
33 Correct 214 ms 39772 KB Output is correct
34 Correct 185 ms 34168 KB Output is correct
35 Correct 25 ms 24704 KB Output is correct
36 Correct 30 ms 25080 KB Output is correct
37 Correct 71 ms 28920 KB Output is correct