Submission #1180933

#TimeUsernameProblemLanguageResultExecution timeMemory
1180933meicrisMarshmallow Molecules (CCO19_day2problem2)C++17
5 / 25
4096 ms37672 KiB
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int MAX=100005;
vector<int> grafo [MAX];
void revisar_vecinos(int nodo){
    vector<int> vecinos = grafo[nodo];
    sort(vecinos.begin(), vecinos.end());
    for (int i = 0; i < vecinos.size(); ++i) {
        for (int j = i + 1; j < vecinos.size(); ++j) {
            int u = vecinos[i];
            int v = vecinos[j];
            if (u > nodo && v > nodo && u!=v) {
                if (find(grafo[v].begin(), grafo[v].end(), u) == grafo[v].end()) {
                    grafo[v].push_back(u);
                    grafo[u].push_back(v);
                }
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, q;
    cin >> n >> q;
    int a, b;
    while (q--) {
        cin >> a >> b;
        grafo[b].push_back(a);
        grafo[a].push_back(b);
    }
    int total=0;
    for (int i = 1; i <= n; i++) {
        revisar_vecinos(i);
        total += grafo[i].size();
    }
    cout<<total/2;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...