Submission #639591

# Submission time Handle Problem Language Result Execution time Memory
639591 2022-09-10T17:10:15 Z Pietra Monthly railway pass (LMIO18_menesinis_bilietas) C++17
100 / 100
1097 ms 96724 KB
// qr ficar na cidade que torna mais barato - ele n paga metro
// mas paga trem
// quais cidades ele teria q ir de onibus visitar?
// pode pegar no max um onibus
// resume as componentes q tem metro
// trata como um grafo com essas comps (salvando o size)
// e as linhas de onibus p conectar
// considera apenas os caras q tem ligação pra tds comps como resp
#include<bits/stdc++.h>
using namespace std ;

const int maxn = 5e5 + 5 ;

int n, m, vis[maxn], sz[maxn], comp[maxn], ct ;
vector<pair<int,int>> bus ;
vector<int> grafo[maxn], tree[maxn] ;
map<pair<int,int>, int> mp ;

void dfs(int v, int p){
    vis[v] = 1, comp[v] = ct ;
    sz[ct]++ ;
    for(auto a : grafo[v]){
        if(vis[a] || a == p) continue ;
        dfs(a, v) ;
    }
}

int main(){

    cin >> n >> m ;

    for(int i = 1 ; i <= m ; i++){
        int a, b ; char t ; cin >> a >> b >> t ;
        if(t == 'T') grafo[a].push_back(b), grafo[b].push_back(a) ;
        else bus.push_back({a, b}) ;
    }

    for(int i = 1 ; i <= n ; i++){
        if(!vis[i]){
            ct++ ;
            dfs(i, i) ;
        }
    }

    for(auto a : bus){
        int x = a.first, y = a.second ;
        if(comp[x] != comp[y] && mp.find({comp[x], comp[y]}) == mp.end()){
            mp[{comp[x], comp[y]}] = 1, mp[{comp[y], comp[x]}] = 1 ;
            tree[comp[x]].push_back(comp[y]), tree[comp[y]].push_back(comp[x]) ;
        }
    }

    int ans = 0 ;

    for(int i = 1 ; i <= ct ; i++){
           // cout << grafo[i].size() << "\n" ;
            if(tree[i].size() >= ct - 1) ans += sz[i] ;
    }

    cout << ans << "\n" ;

}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:57:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |             if(tree[i].size() >= ct - 1) ans += sz[i] ;
      |                ~~~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 520 ms 43476 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 12 ms 23804 KB Output is correct
4 Correct 17 ms 29268 KB Output is correct
5 Correct 12 ms 23916 KB Output is correct
6 Correct 144 ms 26568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 29268 KB Output is correct
2 Correct 12 ms 23916 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 15 ms 23856 KB Output is correct
5 Correct 22 ms 24800 KB Output is correct
6 Correct 951 ms 73216 KB Output is correct
7 Correct 1097 ms 96724 KB Output is correct
8 Correct 31 ms 26452 KB Output is correct
9 Correct 51 ms 28196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 12 ms 23804 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 15 ms 23856 KB Output is correct
5 Correct 22 ms 24800 KB Output is correct
6 Correct 11 ms 23808 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 15 ms 23764 KB Output is correct
9 Correct 14 ms 23920 KB Output is correct
10 Correct 18 ms 24020 KB Output is correct
11 Correct 16 ms 24148 KB Output is correct
12 Correct 14 ms 23764 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 19 ms 24164 KB Output is correct
15 Correct 13 ms 23712 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 12 ms 23732 KB Output is correct
18 Correct 14 ms 23888 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Correct 14 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23808 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 15 ms 23764 KB Output is correct
4 Correct 14 ms 23920 KB Output is correct
5 Correct 18 ms 24020 KB Output is correct
6 Correct 16 ms 24148 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 19 ms 24164 KB Output is correct
10 Correct 13 ms 23712 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 12 ms 23732 KB Output is correct
13 Correct 14 ms 23888 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 14 ms 23892 KB Output is correct
16 Correct 11 ms 23764 KB Output is correct
17 Correct 12 ms 23804 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 15 ms 23856 KB Output is correct
20 Correct 22 ms 24800 KB Output is correct
21 Correct 12 ms 23916 KB Output is correct
22 Correct 31 ms 26452 KB Output is correct
23 Correct 51 ms 28196 KB Output is correct
24 Correct 144 ms 26568 KB Output is correct
25 Correct 32 ms 24212 KB Output is correct
26 Correct 292 ms 28308 KB Output is correct
27 Correct 100 ms 25960 KB Output is correct
28 Correct 281 ms 41532 KB Output is correct
29 Correct 89 ms 25528 KB Output is correct
30 Correct 240 ms 39288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23808 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 15 ms 23764 KB Output is correct
4 Correct 14 ms 23920 KB Output is correct
5 Correct 18 ms 24020 KB Output is correct
6 Correct 16 ms 24148 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 19 ms 24164 KB Output is correct
10 Correct 13 ms 23712 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 12 ms 23732 KB Output is correct
13 Correct 14 ms 23888 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 14 ms 23892 KB Output is correct
16 Correct 32 ms 24212 KB Output is correct
17 Correct 292 ms 28308 KB Output is correct
18 Correct 100 ms 25960 KB Output is correct
19 Correct 281 ms 41532 KB Output is correct
20 Correct 89 ms 25528 KB Output is correct
21 Correct 240 ms 39288 KB Output is correct
22 Correct 520 ms 43476 KB Output is correct
23 Correct 11 ms 23764 KB Output is correct
24 Correct 12 ms 23804 KB Output is correct
25 Correct 17 ms 29268 KB Output is correct
26 Correct 13 ms 23764 KB Output is correct
27 Correct 15 ms 23856 KB Output is correct
28 Correct 22 ms 24800 KB Output is correct
29 Correct 12 ms 23916 KB Output is correct
30 Correct 951 ms 73216 KB Output is correct
31 Correct 1097 ms 96724 KB Output is correct
32 Correct 31 ms 26452 KB Output is correct
33 Correct 51 ms 28196 KB Output is correct
34 Correct 144 ms 26568 KB Output is correct
35 Correct 68 ms 27488 KB Output is correct
36 Correct 422 ms 36916 KB Output is correct
37 Correct 231 ms 31948 KB Output is correct