# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850136 | 2023-09-15T19:48:39 Z | HoriaHaivas | Bread First Search (CCO21_day2problem2) | C++14 | 2 ms | 5960 KB |
/* "TLE is like the wind, always by my side" - Yasuo - 2022 - */ #include<bits/stdc++.h> #define debug(x) cerr << #x << " " << x << "\n" #define debugs(x) cerr << #x << " " << x << " " #pragma GCC optimize("Ofast") using namespace std; struct VOLUNTARI { int node; int dist; }; const int inf=200001; vector<int> nodes[200001]; int distans[200001]; bool visited[200001]; int n; queue<VOLUNTARI> q; void bfs(int source) { int j; for (j=1;j<=n;j++) { distans[j]=inf; visited[j]=0; } q.push({source,0}); VOLUNTARI fr; while (!q.empty()) { fr=q.front(); if (!visited[fr.node]) { visited[fr.node]=1; distans[fr.node]=fr.dist; for (j=0;j<nodes[fr.node].size();j++) { q.push({nodes[fr.node][j],fr.dist+1}); } } q.pop(); } } bool sorteaza (int prefixlen) { int j; for (j=2;j<=prefixlen;j++) { nodes[1].push_back(j); nodes[j].push_back(1); } bfs(1); for (j=prefixlen;j>=2;j--) { nodes[1].pop_back(); nodes[j].pop_back(); } bool ok; ok=true; for (j=2;j<=n;j++) { if (distans[j]<distans[j-1] || !visited[j]) ok=false; } return ok; } int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); int m,i,j,k,r,pas,u,v,ans; cin >> n >> m; for (j=1;j<=m;j++) { cin >> u >> v; nodes[u].push_back(v); nodes[v].push_back(u); } r=0; pas=(1<<17); while(pas) { if (r+pas<=n && !sorteaza(r+pas)) r+=pas; pas=pas/2; } r++; bfs(1); ans=0; for (j=1;j<=r;j++) { if (distans[j]==1 || j==1) r--; } cout << r; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5724 KB | Output is correct |
2 | Correct | 1 ms | 5724 KB | Output is correct |
3 | Correct | 2 ms | 5724 KB | Output is correct |
4 | Incorrect | 2 ms | 5960 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5724 KB | Output is correct |
2 | Correct | 1 ms | 5724 KB | Output is correct |
3 | Correct | 2 ms | 5724 KB | Output is correct |
4 | Incorrect | 2 ms | 5960 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 5724 KB | Output is correct |
2 | Correct | 1 ms | 5724 KB | Output is correct |
3 | Correct | 2 ms | 5724 KB | Output is correct |
4 | Incorrect | 2 ms | 5960 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |