Title Link: Https://cn.vjudge.net/problem/CodeForces-920E
Test instructions
Give a fill map, ask each unicom block has several elements, ascending order
Note Maxn=2e5, Maxm=2e10
Ideas
The amount of data is very large, which would have been a topic of research and
If you use and look up a set, maintain an element number up, but first offline mapping is a problem O (n^2)
If you think about it, BFS O (n) is a better choice.
Submitted to the tle, at that time writing the problem is not careful calculation of complexity, set check Edge + array weight, add up looks like O (nlogn+n), as to why with Set check edge, because the array is too large to check the edge
Finally check the puzzle, the weight is linked list deleted elements, equivalent to the actual deletion, the number of cycles greatly reduced
Okay, great.
Submission Process
Ce |
Header file |
TLE1 |
Set<pair<int, int>> storage Edge |
TLE2 |
Change to set |
Wa1-3 |
Forget why WA ... |
AC |
|
Code
#include <set> #include <queue> #include <cstdio> #include <cstring> #include <algorithm> using namespace Std;const int maxn=2e5+20;int n, m, CNT, SIZE[MAXN], NEXT[MAXN], Prev[maxn];bool check[maxn];set<long l ong> vis;void del (int x) {next[prev[x]]=next[x]; PREV[NEXT[X]]=PREV[X];} int BFS (int x) {int ans=1; Queue<int> que; Que.push (x); Check[x]=true; Del (x); while (Que.size ()) {int Node=que.front (); Que.pop (); for (int i=next[0]; i<=n; i=next[i]) if (!check[i] &&!vis.count ((Long Long) i*maxn+node) {Que.push ( i); Check[i]=true; Del (i); ans++; }}return ans; int main (void) {int to, from; scanf ("%d%d", &n, &m); for (int i=0; i<m; i++) {scanf ("%d%d", &to, &from); Vis.insert ((Long Long) to*maxn+from); Vis.insert ((Long Long) from*maxn+to); } for (int i=1; i<=n; i++) next[i]=i+1, prev[i]=i-1; Next[0]=1; Prev[n+1]=n; int cnt=0; for (int i=1; i<=n; i++) if (!check[i]) size[cnt++]=bfs (i); Sort (size, size+cnt); printf ("%d\n", CNT); for (int i=0; i<cnt; i++) printf ("%d%c", size[i], "\ n" [i==cnt-1]); return 0;}
| Time
Memory |
Length |
Lang |
submitted |
343ms |
16012kB |
1067 |
GNU g++ 5.1.0 |
2018-07-23 17:51:00 |
CODEFORCES-920E Connected components? Breadth Search to judge the deletion of duplicate points under large data of Unicom