結果
問題 | No.416 旅行会社 |
ユーザー |
![]() |
提出日時 | 2017-08-28 19:21:20 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 304 ms / 4,000 ms |
コード長 | 2,339 bytes |
コンパイル時間 | 1,544 ms |
コンパイル使用メモリ | 174,060 KB |
実行使用メモリ | 19,200 KB |
最終ジャッジ日時 | 2024-12-14 20:24:45 |
合計ジャッジ時間 | 5,533 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
コンパイルメッセージ
main.cpp:77:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 77 | main(){ | ^~~~ main.cpp: In function ‘int main()’: main.cpp:97:27: warning: iteration 100000 invokes undefined behavior [-Waggressive-loop-optimizations] 97 | FOR(i, 1, 100002)ans[i] = -1; | ~~~~~~~^~~~ main.cpp:2:36: note: within this loop 2 | #define FOR(i,a,b) for (int i=(a);i<(b);i++) | ^ main.cpp:97:3: note: in expansion of macro ‘FOR’ 97 | FOR(i, 1, 100002)ans[i] = -1; | ^~~ main.cpp:97:27: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’ writing 400004 bytes into a region of size 400000 overflows the destination [-Wstringop-overflow=] 97 | FOR(i, 1, 100002)ans[i] = -1; | ~~~~~~~^~~~ main.cpp:72:5: note: at offset 4 into destination object ‘ans’ of size 400004 72 | int ans[100001]; | ^~~
ソースコード
#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, tailvoid 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, 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){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, -1);}FOR(i, 1, 100002)ans[i] = -1;FORR(i, q-1, 0) uf.merge(Q[i].fi, Q[i].se, i+1);FOR(i, 2, n+1) cout << uf.ans[i] << "\n";}