답안 #258739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258739 2020-08-06T13:08:38 Z uacoder123 Monthly railway pass (LMIO18_menesinis_bilietas) C++14
100 / 100
974 ms 72484 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))

typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <ii,lli> iii;
typedef vector <lli> vi;
set<int> al[500001];
int n,m,t,co=0;
int par[500001],r[500001]={};
vector<ii> ed;
int find(int f)
{
    if(par[par[f]]!=par[f]) par[f]=find(par[f]);
    return(par[f]);
}
void mer(int f,int s)
{
    int pf=find(f),ps=find(s);
    if(pf!=ps)
    {
        if(r[pf]>=r[ps])
        {
            par[ps]=pf;
            if(r[ps]==r[pf])
            r[pf]++;
        }
        else
        {
            par[pf]=ps;
            if(r[ps]==r[pf])
            r[ps]++;
        }
        t--;
    }
}
int main()
{
    cin>>n>>m;
    t=n;
    for(int i=1;i<=n;++i)
    {
        par[i]=i;
        r[i]=1;
    }
    for(int i=0;i<m;++i)
    {
        char c;
        int f,s;
        cin>>f>>s>>c;
        if(c=='A')
            ed.pb(mp(f,s));
        else
            mer(f,s);
    }
    for(int i=0;i<ed.size();++i)
    {
        int pf=find(ed[i].F),ps=find(ed[i].S);
        if(ps!=pf)
        {
            al[pf].insert(ps);
            al[ps].insert(pf);
        }
    }
    for(int i=1;i<=n;++i)
        if(al[find(i)].size()>=t-1)
            co++;
    cout<<co<<endl;
    return(0);
} 

Compilation message

menesinis_bilietas.cpp: In function 'int main()':
menesinis_bilietas.cpp:65:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ed.size();++i)
                 ~^~~~~~~~~~
menesinis_bilietas.cpp:75:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(al[find(i)].size()>=t-1)
            ~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 511 ms 27320 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 18 ms 27520 KB Output is correct
5 Correct 14 ms 23936 KB Output is correct
6 Correct 190 ms 24928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27520 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 17 ms 23936 KB Output is correct
4 Correct 24 ms 24696 KB Output is correct
5 Correct 14 ms 23936 KB Output is correct
6 Correct 784 ms 61280 KB Output is correct
7 Correct 974 ms 72484 KB Output is correct
8 Correct 33 ms 25716 KB Output is correct
9 Correct 56 ms 27312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 22 ms 24320 KB Output is correct
6 Correct 20 ms 24192 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 25 ms 24332 KB Output is correct
10 Correct 14 ms 23808 KB Output is correct
11 Correct 16 ms 23876 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 16 ms 23936 KB Output is correct
14 Correct 15 ms 23936 KB Output is correct
15 Correct 16 ms 23936 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 14 ms 23808 KB Output is correct
19 Correct 17 ms 23936 KB Output is correct
20 Correct 24 ms 24696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 22 ms 24320 KB Output is correct
6 Correct 20 ms 24192 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 25 ms 24332 KB Output is correct
10 Correct 14 ms 23808 KB Output is correct
11 Correct 16 ms 23876 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 16 ms 23936 KB Output is correct
14 Correct 15 ms 23936 KB Output is correct
15 Correct 16 ms 23936 KB Output is correct
16 Correct 43 ms 24820 KB Output is correct
17 Correct 400 ms 35804 KB Output is correct
18 Correct 163 ms 29412 KB Output is correct
19 Correct 327 ms 40324 KB Output is correct
20 Correct 136 ms 27364 KB Output is correct
21 Correct 274 ms 37852 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 15 ms 23808 KB Output is correct
24 Correct 14 ms 23808 KB Output is correct
25 Correct 17 ms 23936 KB Output is correct
26 Correct 24 ms 24696 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 33 ms 25716 KB Output is correct
29 Correct 56 ms 27312 KB Output is correct
30 Correct 190 ms 24928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 16 ms 23936 KB Output is correct
4 Correct 18 ms 24064 KB Output is correct
5 Correct 22 ms 24320 KB Output is correct
6 Correct 20 ms 24192 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 25 ms 24332 KB Output is correct
10 Correct 14 ms 23808 KB Output is correct
11 Correct 16 ms 23876 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 16 ms 23936 KB Output is correct
14 Correct 15 ms 23936 KB Output is correct
15 Correct 16 ms 23936 KB Output is correct
16 Correct 43 ms 24820 KB Output is correct
17 Correct 400 ms 35804 KB Output is correct
18 Correct 163 ms 29412 KB Output is correct
19 Correct 327 ms 40324 KB Output is correct
20 Correct 136 ms 27364 KB Output is correct
21 Correct 274 ms 37852 KB Output is correct
22 Correct 511 ms 27320 KB Output is correct
23 Correct 14 ms 23808 KB Output is correct
24 Correct 15 ms 23808 KB Output is correct
25 Correct 18 ms 27520 KB Output is correct
26 Correct 14 ms 23808 KB Output is correct
27 Correct 17 ms 23936 KB Output is correct
28 Correct 24 ms 24696 KB Output is correct
29 Correct 14 ms 23936 KB Output is correct
30 Correct 784 ms 61280 KB Output is correct
31 Correct 974 ms 72484 KB Output is correct
32 Correct 109 ms 27116 KB Output is correct
33 Correct 581 ms 40532 KB Output is correct
34 Correct 232 ms 28536 KB Output is correct
35 Correct 33 ms 25716 KB Output is correct
36 Correct 56 ms 27312 KB Output is correct
37 Correct 190 ms 24928 KB Output is correct