結果

問題 No.416 旅行会社
ユーザー ei1333333ei1333333
提出日時 2016-07-21 23:44:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,415 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 173,476 KB
実行使用メモリ 34,956 KB
最終ジャッジ日時 2024-04-25 13:32:21
合計ジャッジ時間 8,055 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
27,940 KB
testcase_01 AC 6 ms
16,068 KB
testcase_02 AC 6 ms
16,828 KB
testcase_03 AC 5 ms
15,960 KB
testcase_04 AC 6 ms
15,756 KB
testcase_05 AC 6 ms
16,104 KB
testcase_06 AC 6 ms
15,980 KB
testcase_07 AC 5 ms
16,144 KB
testcase_08 AC 9 ms
17,256 KB
testcase_09 AC 22 ms
17,936 KB
testcase_10 AC 138 ms
27,924 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |   scanf("%d %d %d", &N, &M, &Q);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |     scanf("%d %d", &A[i], &B[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:47:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |     scanf("%d %d", &C[i], &D[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;
 
int data[200000];
set< int > zig[200000];
int query[200000];
 
int find(int y)
{
  if(data[y] < 0) return(y);
  return(data[y] = find(data[y]));
}
void unite(int x, int y)
{
  x = find(x);
  y = find(y);
  if(x != y) {
    data[x] += data[y];
    data[y] = x;
    while(!zig[y].empty()) {
      zig[x].insert(*zig[y].begin());
      zig[y].erase(zig[y].begin());
    }
  }
}
 
 
int N, M, Q;
bool v[200000];
int A[200000], B[200000];
int C[200000], D[200000];
 
map< Pi, int > idx;
 
int main()
{
  memset(data, -1, sizeof(data));
  scanf("%d %d %d", &N, &M, &Q);
  for(int i = 0; i < N; i++) zig[i].insert(i);
   
  for(int i = 0; i < M; i++) {
    scanf("%d %d", &A[i], &B[i]);
    idx[minmax(--A[i], --B[i])] = i;
  }
  for(int i = 0; i < Q; i++) {
    scanf("%d %d", &C[i], &D[i]);
    v[idx[minmax(--C[i], --D[i])]] = true;
  }
  for(int i = 0; i < M; i++) {
    if(!v[i]) unite(A[i], B[i]);
  }
   
  while(!zig[find(0)].empty()) {
    query[*zig[find(0)].begin()] = -1;
    zig[find(0)].erase(zig[find(0)].begin());
  }
   
  for(int i = Q - 1; i >= 0; i--) {
    unite(C[i], D[i]);
    if(find(C[i]) == find(0)) {
      while(!zig[find(0)].empty()) {
        query[*zig[find(0)].begin()] = i + 1;
        zig[find(0)].erase(zig[find(0)].begin());
      }
    }
  }
  for(int i = 1; i < N; i++) {
    printf("%d\n", query[i]);
  }
}
0