답안 #821304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
821304 2023-08-11T08:56:11 Z Denkata Marshmallow Molecules (CCO19_day2problem2) C++17
0 / 25
811 ms 1048576 KB
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
const int maxn = 1e5+3;
long long i,j,p,q,n,m,k,cnt[maxn];
vector <int> v[maxn];
vector <int> rev[maxn];
int marked[maxn];
long long ans;
set <int> s[maxn];
set <int> gett(set <int> a,set <int> b)
{
    if(a.size()<b.size())
        swap(a,b);
    a.insert(b.begin(),b.end());
    return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    ans = m;
    for(i=1;i<=m;i++)
    {
        cin>>p>>q;
        s[p].insert(q);
    }
    for(i=1;i<=n;i++)
    {
        if(s[i].empty())continue;
        ans+=max((int)s[i].size()-1,0);
        p = *s[i].begin();
        s[i].erase(s[i].begin());
        s[p] = gett(s[p],s[i]);
    }
    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 7 ms 9876 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 7 ms 9876 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 811 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 7 ms 9876 KB Output isn't correct
4 Halted 0 ms 0 KB -