結果
問題 | No.416 旅行会社 |
ユーザー | char134217728 |
提出日時 | 2017-08-28 19:17:57 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,388 bytes |
コンパイル時間 | 1,621 ms |
コンパイル使用メモリ | 160,492 KB |
実行使用メモリ | 19,280 KB |
最終ジャッジ日時 | 2023-08-06 05:31:43 |
合計ジャッジ時間 | 7,210 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 93 ms
12,052 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 122 ms
11,912 KB |
testcase_11 | AC | 123 ms
11,992 KB |
testcase_12 | AC | 126 ms
12,052 KB |
testcase_13 | AC | 91 ms
11,984 KB |
testcase_14 | AC | 373 ms
19,044 KB |
testcase_15 | AC | 364 ms
19,280 KB |
testcase_16 | AC | 365 ms
19,184 KB |
testcase_17 | AC | 366 ms
19,060 KB |
testcase_18 | AC | 363 ms
19,180 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
コンパイルメッセージ
main.cpp:77:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] main(){ ^ main.cpp: In function ‘int main()’: main.cpp:97:27: warning: iteration 100000 invokes undefined behavior [-Waggressive-loop-optimizations] FOR(i, 1, 100002)ans[i] = -1; ~~~~~~~^~~~ main.cpp:2:36: note: within this loop #define FOR(i,a,b) for (int i=(a);i<(b);i++) ^ main.cpp:97:3: note: in expansion of macro ‘FOR’ FOR(i, 1, 100002)ans[i] = -1; ^~~
ソースコード
#include <bits/stdc++.h> #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back #define pcnt __builtin_popcount #define show(x) cout<<#x<<" = "<<x<<endl; #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define fi first #define se second #define rng(a) a.begin(),a.end() #define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define sz(x) (int)(x).size() using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef set<int> si; typedef pair<ll,ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pll> vpll; typedef set<ll> sl; template<typename T>string join(vector<T>&v) {stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);} ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;} int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;} void dout(double d){printf("%.12f\n",d);} const int iinf = 1e9; const ll linf = 1e18; const int mod = 1e9+7; const double pi = acos(-1); const double eps = 1e-10; struct UnionFind{ int ans[100001]; vi p; vpii li; // next, tail void init(int n){ p.resize(n); li.resize(n); FOR(i, 0, n) p[i] = -1; FOR(i, 0, n) li[i] = pii(-1, i); } int find(int a){ if(p[a] < 0) return a; p[a] = find(p[a]); return p[a]; } void merge(int a, int b, bool z, int q){ a = find(a); b = find(b); if(a == b) return; if(a > b) swap(a, b); p[b] = a; li[li[a].se].fi = b; li[a].se = li[b].se; if(a == 1 && z){ int id = b; while(id > 0){ ans[id] = q; id = li[id].fi; } } } }; int ans[100001]; int n, m, q; UnionFind uf; map<pii, bool> e; pii Q[200000]; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> q; uf.init(n + 1); FOR(i, 0, m){ int a, b; cin >> a >> b; e[pii(a, b)] = true; } FOR(i, 0, q){ int c, d; cin >> c >> d; Q[i] = pii(c, d); e[Q[i]] = false; } each(itr, e){ if(!itr->se)continue; uf.merge(itr->fi.fi, itr->fi.se, false, 0); } FOR(i, 1, 100002)ans[i] = -1; FORR(i, q-1, 0) uf.merge(Q[i].fi, Q[i].se, true, i+1); FOR(i, 2, n+1) cout << (uf.ans[i] == 0 ? -1 : uf.ans[i] )<< "\n"; }