Submission #821258

# Submission time Handle Problem Language Result Execution time Memory
821258 2023-08-11T08:30:15 Z DobromirAngelov Marshmallow Molecules (CCO19_day2problem2) C++14
10 / 25
33 ms 4832 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MAXN=1e5+5;

int n,m;
vector<int> adj[MAXN];
bool used[MAXN];
long long ans=0;
bool g[105][105];

void solve(int v)
{
    used[v]=1;
    priority_queue<int> pq;
    pq.push(-v);
    while(!pq.empty())
    {
        v=-pq.top();
        pq.pop();
        int bef=pq.size();
        int br=0;
        for(int i=0;i<adj[v].size();i++)
        {
            if(!used[adj[v][i]])
            {
                used[adj[v][i]]=1;
                pq.push(-adj[v][i]);
                br++;
            }
        }
        ans+=br;
        ans+=(long long) br*bef;
        ans+=(long long) br*(br-1)/2;
    }
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

cin>>n>>m;
for(int i=0;i<m;i++)
{
    int u,v;
    cin>>u>>v;
    adj[u].push_back(v);
    if(n<=100) g[u][v]=1;
}

if(n<=100)
{
    for(int i=1;i<=n;i++)
    {
        vector<int> v;
        for(int j=i+1;j<=n;j++)
        {
            if(g[i][j]) v.push_back(j);
        }
        for(int j=0;j<v.size();j++)
        {
            for(int k=j+1;k<v.size();k++)
            {
                g[v[j]][v[k]]=1;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++) if(g[i][j]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

for(int i=1;i<=n;i++)
{
    if(!used[i])
    {
        if(adj[i].size()==0) continue;
        solve(i);
    }
}

cout<<ans<<endl;

return 0;
}

Compilation message

Main.cpp: In function 'void solve(int)':
Main.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int i=0;i<adj[v].size();i++)
      |                     ~^~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for(int j=0;j<v.size();j++)
      |                     ~^~~~~~~~~
Main.cpp:66:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             for(int k=j+1;k<v.size();k++)
      |                           ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2696 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2696 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Incorrect 14 ms 3428 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4380 KB Output is correct
2 Correct 29 ms 4696 KB Output is correct
3 Correct 28 ms 4832 KB Output is correct
4 Correct 27 ms 4180 KB Output is correct
5 Correct 29 ms 4788 KB Output is correct
6 Correct 27 ms 4788 KB Output is correct
7 Correct 27 ms 4432 KB Output is correct
8 Correct 28 ms 4764 KB Output is correct
9 Correct 27 ms 4740 KB Output is correct
10 Correct 26 ms 4324 KB Output is correct
11 Correct 30 ms 4688 KB Output is correct
12 Correct 30 ms 4808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2696 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Incorrect 14 ms 3428 KB Output isn't correct
17 Halted 0 ms 0 KB -