# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
825990 | 2023-08-15T09:45:07 Z | AlphaMale06 | Monthly railway pass (LMIO18_menesinis_bilietas) | C++14 | 292 ms | 262144 KB |
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define mp make_pair #define pb push_back const int N = 5000005; int p[N]; int sz[N]; //set<int> reps; set<int> adj[N]; vector<pair<int, int>> paid; void make(int v){p[v]=v; sz[v]=1;} int rep(int v){ if(p[v]==v)return v; return p[v]=rep(p[v]); } void unite(int v, int u){ v=rep(v); u=rep(u); if(u==v)return; if(sz[u]>sz[v]){ swap(u, v); } p[u]=v; sz[v]+=sz[u]; //reps.erase(reps.find(u)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for(int i=1; i<=n; i++){ make(i); // reps.insert(i); } for(int i=0; i< m; i++){ int x, y; char a; cin >> x >> y >> a; if(a=='T'){ unite(x, y); } else paid.pb(mp(x, y)); } for(int i=0; i< paid.size(); i++){ int x=paid[i].F; int y=paid[i].S; x=rep(x); y=rep(y); if(x==y)continue; adj[x].insert(y); adj[y].insert(x); } int ans=0; int cnt=0; for(int i=1; i<=n; i++){ if(p[i]==i)cnt++; } for(int i=1; i<=n; i++){ if(p[i]==i){ if(adj[i].size()==cnt-1)ans+=sz[i]; } } //for(auto it = reps.begin(); it!=reps.end(); it++){ // int node=*it; // if(adj[node].size()==reps.size()-1){ // ans+=sz[node]; // } //} cout << ans << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 167 ms | 238504 KB | Output is correct |
2 | Correct | 97 ms | 235224 KB | Output is correct |
3 | Correct | 93 ms | 235160 KB | Output is correct |
4 | Correct | 100 ms | 238832 KB | Output is correct |
5 | Correct | 108 ms | 235148 KB | Output is correct |
6 | Correct | 119 ms | 236164 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 100 ms | 238832 KB | Output is correct |
2 | Correct | 108 ms | 235148 KB | Output is correct |
3 | Correct | 99 ms | 235272 KB | Output is correct |
4 | Correct | 94 ms | 235204 KB | Output is correct |
5 | Correct | 107 ms | 235952 KB | Output is correct |
6 | Runtime error | 292 ms | 262144 KB | Execution killed with signal 9 |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 97 ms | 235224 KB | Output is correct |
2 | Correct | 93 ms | 235160 KB | Output is correct |
3 | Correct | 99 ms | 235272 KB | Output is correct |
4 | Correct | 94 ms | 235204 KB | Output is correct |
5 | Correct | 107 ms | 235952 KB | Output is correct |
6 | Correct | 117 ms | 235128 KB | Output is correct |
7 | Correct | 97 ms | 235164 KB | Output is correct |
8 | Correct | 97 ms | 235224 KB | Output is correct |
9 | Correct | 98 ms | 235192 KB | Output is correct |
10 | Correct | 104 ms | 235384 KB | Output is correct |
11 | Correct | 98 ms | 235372 KB | Output is correct |
12 | Correct | 96 ms | 235200 KB | Output is correct |
13 | Correct | 99 ms | 235192 KB | Output is correct |
14 | Correct | 108 ms | 235544 KB | Output is correct |
15 | Correct | 98 ms | 235056 KB | Output is correct |
16 | Correct | 98 ms | 235112 KB | Output is correct |
17 | Correct | 96 ms | 235104 KB | Output is correct |
18 | Correct | 99 ms | 235256 KB | Output is correct |
19 | Correct | 100 ms | 235108 KB | Output is correct |
20 | Correct | 100 ms | 235208 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 117 ms | 235128 KB | Output is correct |
2 | Correct | 97 ms | 235164 KB | Output is correct |
3 | Correct | 97 ms | 235224 KB | Output is correct |
4 | Correct | 98 ms | 235192 KB | Output is correct |
5 | Correct | 104 ms | 235384 KB | Output is correct |
6 | Correct | 98 ms | 235372 KB | Output is correct |
7 | Correct | 96 ms | 235200 KB | Output is correct |
8 | Correct | 99 ms | 235192 KB | Output is correct |
9 | Correct | 108 ms | 235544 KB | Output is correct |
10 | Correct | 98 ms | 235056 KB | Output is correct |
11 | Correct | 98 ms | 235112 KB | Output is correct |
12 | Correct | 96 ms | 235104 KB | Output is correct |
13 | Correct | 99 ms | 235256 KB | Output is correct |
14 | Correct | 100 ms | 235108 KB | Output is correct |
15 | Correct | 100 ms | 235208 KB | Output is correct |
16 | Correct | 97 ms | 235224 KB | Output is correct |
17 | Correct | 93 ms | 235160 KB | Output is correct |
18 | Correct | 99 ms | 235272 KB | Output is correct |
19 | Correct | 94 ms | 235204 KB | Output is correct |
20 | Correct | 107 ms | 235952 KB | Output is correct |
21 | Correct | 108 ms | 235148 KB | Output is correct |
22 | Correct | 119 ms | 236164 KB | Output is correct |
23 | Correct | 104 ms | 235856 KB | Output is correct |
24 | Correct | 181 ms | 240776 KB | Output is correct |
25 | Correct | 136 ms | 238584 KB | Output is correct |
26 | Correct | 209 ms | 249356 KB | Output is correct |
27 | Correct | 125 ms | 237768 KB | Output is correct |
28 | Correct | 176 ms | 247104 KB | Output is correct |
29 | Correct | 105 ms | 236912 KB | Output is correct |
30 | Correct | 119 ms | 238516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 117 ms | 235128 KB | Output is correct |
2 | Correct | 97 ms | 235164 KB | Output is correct |
3 | Correct | 97 ms | 235224 KB | Output is correct |
4 | Correct | 98 ms | 235192 KB | Output is correct |
5 | Correct | 104 ms | 235384 KB | Output is correct |
6 | Correct | 98 ms | 235372 KB | Output is correct |
7 | Correct | 96 ms | 235200 KB | Output is correct |
8 | Correct | 99 ms | 235192 KB | Output is correct |
9 | Correct | 108 ms | 235544 KB | Output is correct |
10 | Correct | 98 ms | 235056 KB | Output is correct |
11 | Correct | 98 ms | 235112 KB | Output is correct |
12 | Correct | 96 ms | 235104 KB | Output is correct |
13 | Correct | 99 ms | 235256 KB | Output is correct |
14 | Correct | 100 ms | 235108 KB | Output is correct |
15 | Correct | 100 ms | 235208 KB | Output is correct |
16 | Correct | 104 ms | 235856 KB | Output is correct |
17 | Correct | 181 ms | 240776 KB | Output is correct |
18 | Correct | 136 ms | 238584 KB | Output is correct |
19 | Correct | 209 ms | 249356 KB | Output is correct |
20 | Correct | 125 ms | 237768 KB | Output is correct |
21 | Correct | 176 ms | 247104 KB | Output is correct |
22 | Correct | 167 ms | 238504 KB | Output is correct |
23 | Correct | 97 ms | 235224 KB | Output is correct |
24 | Correct | 93 ms | 235160 KB | Output is correct |
25 | Correct | 100 ms | 238832 KB | Output is correct |
26 | Correct | 99 ms | 235272 KB | Output is correct |
27 | Correct | 94 ms | 235204 KB | Output is correct |
28 | Correct | 107 ms | 235952 KB | Output is correct |
29 | Correct | 108 ms | 235148 KB | Output is correct |
30 | Runtime error | 292 ms | 262144 KB | Execution killed with signal 9 |
31 | Halted | 0 ms | 0 KB | - |