Submission #1096934

# Submission time Handle Problem Language Result Execution time Memory
1096934 2024-10-05T13:14:08 Z ivaziva Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
429 ms 85816 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 1000001

int n,m;
vector<int> adj[2][MAXN];
int komp[MAXN],siz[MAXN],tren=0;
bool pos[MAXN];
vector<int> koren;
set<int> komponente;

void dfs(int node)
{
    pos[node]=true;komp[node]=tren;siz[tren]++;
    for (int sled:adj[0][node])
    {
        if (pos[sled]==true) continue;
        else dfs(sled);
    }
}

void dfs1(int node)
{
    pos[node]=true;
    for (int sled:adj[1][node]) 
    {
        if (komp[sled]==komp[node]) continue;
        else komponente.insert(komp[sled]);
    }
    for (int sled:adj[0][node])
    {
        if (pos[sled]==true) continue;
        else dfs1(sled);
    }
}

int main()
{
    cin>>n>>m;
    for (int i=1;i<=m;i++)
    {
        int x,y;cin>>x>>y;char c;cin>>c;
        if (c=='T') {adj[0][x].push_back(y);adj[0][y].push_back(x);}
        else {adj[1][x].push_back(y);adj[1][y].push_back(x);}
    }
    koren.push_back(0);
    for (int i=1;i<=n;i++)
    {
        if (pos[i]==true) continue;
        else {koren.push_back(i);tren++;dfs(i);}
    }
    for (int i=1;i<=n;i++) pos[i]=false;
    int ans=0;
    for (int i=1;i<=tren;i++)
    {
        dfs1(koren[i]);
        if (komponente.size()==tren-1) ans+=siz[i];
        komponente.clear();
    }
    cout<<ans<<endl;
}

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:59:30: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |         if (komponente.size()==tren-1) ans+=siz[i];
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 370 ms 73044 KB Output is correct
2 Correct 20 ms 47192 KB Output is correct
3 Correct 22 ms 47452 KB Output is correct
4 Correct 28 ms 53344 KB Output is correct
5 Correct 22 ms 47452 KB Output is correct
6 Correct 97 ms 50528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 53344 KB Output is correct
2 Correct 22 ms 47452 KB Output is correct
3 Correct 22 ms 47196 KB Output is correct
4 Correct 22 ms 47368 KB Output is correct
5 Correct 23 ms 47424 KB Output is correct
6 Correct 258 ms 54028 KB Output is correct
7 Correct 429 ms 85816 KB Output is correct
8 Correct 32 ms 48720 KB Output is correct
9 Correct 37 ms 48724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47192 KB Output is correct
2 Correct 22 ms 47452 KB Output is correct
3 Correct 22 ms 47196 KB Output is correct
4 Correct 22 ms 47368 KB Output is correct
5 Correct 23 ms 47424 KB Output is correct
6 Correct 21 ms 47196 KB Output is correct
7 Correct 22 ms 47196 KB Output is correct
8 Correct 21 ms 47452 KB Output is correct
9 Correct 22 ms 47448 KB Output is correct
10 Correct 24 ms 47400 KB Output is correct
11 Correct 23 ms 47452 KB Output is correct
12 Correct 23 ms 47196 KB Output is correct
13 Correct 22 ms 47192 KB Output is correct
14 Correct 28 ms 47452 KB Output is correct
15 Correct 21 ms 47192 KB Output is correct
16 Correct 20 ms 47448 KB Output is correct
17 Correct 19 ms 47196 KB Output is correct
18 Correct 20 ms 47256 KB Output is correct
19 Correct 19 ms 47448 KB Output is correct
20 Correct 20 ms 47704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 47196 KB Output is correct
2 Correct 22 ms 47196 KB Output is correct
3 Correct 21 ms 47452 KB Output is correct
4 Correct 22 ms 47448 KB Output is correct
5 Correct 24 ms 47400 KB Output is correct
6 Correct 23 ms 47452 KB Output is correct
7 Correct 23 ms 47196 KB Output is correct
8 Correct 22 ms 47192 KB Output is correct
9 Correct 28 ms 47452 KB Output is correct
10 Correct 21 ms 47192 KB Output is correct
11 Correct 20 ms 47448 KB Output is correct
12 Correct 19 ms 47196 KB Output is correct
13 Correct 20 ms 47256 KB Output is correct
14 Correct 19 ms 47448 KB Output is correct
15 Correct 20 ms 47704 KB Output is correct
16 Correct 20 ms 47192 KB Output is correct
17 Correct 22 ms 47452 KB Output is correct
18 Correct 22 ms 47196 KB Output is correct
19 Correct 22 ms 47368 KB Output is correct
20 Correct 23 ms 47424 KB Output is correct
21 Correct 22 ms 47452 KB Output is correct
22 Correct 32 ms 48720 KB Output is correct
23 Correct 37 ms 48724 KB Output is correct
24 Correct 97 ms 50528 KB Output is correct
25 Correct 29 ms 47704 KB Output is correct
26 Correct 175 ms 52788 KB Output is correct
27 Correct 75 ms 49236 KB Output is correct
28 Correct 98 ms 49964 KB Output is correct
29 Correct 58 ms 48976 KB Output is correct
30 Correct 113 ms 50004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 47196 KB Output is correct
2 Correct 22 ms 47196 KB Output is correct
3 Correct 21 ms 47452 KB Output is correct
4 Correct 22 ms 47448 KB Output is correct
5 Correct 24 ms 47400 KB Output is correct
6 Correct 23 ms 47452 KB Output is correct
7 Correct 23 ms 47196 KB Output is correct
8 Correct 22 ms 47192 KB Output is correct
9 Correct 28 ms 47452 KB Output is correct
10 Correct 21 ms 47192 KB Output is correct
11 Correct 20 ms 47448 KB Output is correct
12 Correct 19 ms 47196 KB Output is correct
13 Correct 20 ms 47256 KB Output is correct
14 Correct 19 ms 47448 KB Output is correct
15 Correct 20 ms 47704 KB Output is correct
16 Correct 29 ms 47704 KB Output is correct
17 Correct 175 ms 52788 KB Output is correct
18 Correct 75 ms 49236 KB Output is correct
19 Correct 98 ms 49964 KB Output is correct
20 Correct 58 ms 48976 KB Output is correct
21 Correct 113 ms 50004 KB Output is correct
22 Correct 370 ms 73044 KB Output is correct
23 Correct 20 ms 47192 KB Output is correct
24 Correct 22 ms 47452 KB Output is correct
25 Correct 28 ms 53344 KB Output is correct
26 Correct 22 ms 47196 KB Output is correct
27 Correct 22 ms 47368 KB Output is correct
28 Correct 23 ms 47424 KB Output is correct
29 Correct 22 ms 47452 KB Output is correct
30 Correct 258 ms 54028 KB Output is correct
31 Correct 429 ms 85816 KB Output is correct
32 Correct 32 ms 48720 KB Output is correct
33 Correct 37 ms 48724 KB Output is correct
34 Correct 97 ms 50528 KB Output is correct
35 Correct 54 ms 50084 KB Output is correct
36 Correct 263 ms 62136 KB Output is correct
37 Correct 156 ms 57932 KB Output is correct