Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<algorithm>
- #define MAX_M 300010
- #define MAX_N 7010
- using namespace std;
- int n,m;
- bool ans[MAX_M];
- int head[MAX_N];
- struct edge_tag {
- int x,y,w;
- int id;
- } edge[MAX_M];
- bool cmp( edge_tag a , edge_tag b )
- {
- return a.w < b.w;
- }
- int findhead(int h)
- {
- if( head[h] != h ) head[h] = findhead( head[h] );
- return head[h];
- }
- int main()
- {
- scanf("%d%d",&n,&m);
- for(int c=1;c<=n;c++) head[c] = c;
- for(int c=1;c<=m;c++)
- {
- scanf("%d%d%d",&edge[c].x,&edge[c].y,&edge[c].w);
- edge[c].id = c;
- }
- sort( edge+1 , edge+m+1 , cmp );
- for(int c=1;c<=m;c++)
- {
- if( edge[c].w != edge[c-1].w )
- {
- for(int d=c;d<=m and edge[d].w==edge[c].w;d++) if( findhead( edge[d].x ) != findhead( edge[d].y ) ) ans[ edge[d].id ] = true;
- }
- int x = findhead( edge[c].x ), y = findhead( edge[c].y );
- head[x] = head[y] = min( x ,y );
- }
- for(int c=1;c<=m;c++) if( ans[c] == 1 ) printf("TAK\n"); else printf("NIE\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement