Submission #1694107
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
int n,m;
vector<pair<int,int>> g[400005]; // to, e-idx
int a[500005], b[500005];
int lft[400005];
int val[400005];
int use[500005];
bool usedImos[500005], isBridge[500005], visited[400005];
int imos[400005];
void dfsInit(int v, int from){
visited[v] = true;
for(auto to : g[v]) if(to.fi != from){
if(visited[to.fi]){
int i = to.se;
if(usedImos[i]) continue;
if(v == a[i]) imos[a[i]]++, imos[b[i]]--;
else imos[a[i]]--, imos[b[i]]++;
usedImos[i]=true;
} else {
dfsInit(to.fi, v);
}
}
}
int dfsBridge(int v){
int ret = imos[v];
visited[v] = true;
for(auto to : g[v]) if(!visited[to.fi]){
int r = dfsBridge(to.fi);
if(r==0) isBridge[to.se] = true;
else isBridge[to.se] = false;
ret += r;
}
return ret;
}
void dfs(int v);
inline void useEdge(int e, int x){
use[e] = x;
lft[a[e]]--; lft[b[e]]--;
val[a[e]] += x; val[b[e]] += x;
if(lft[a[e]]==1) dfs(a[e]);
if(lft[b[e]]==1) dfs(b[e]);
}
void dfs(int v){
assert(lft[v]==1);
pair<int,int> nxt;
for(auto &p: g[v]) if(use[p.se]==0) nxt = p;
useEdge(nxt.se, 2 - val[v]%2);
}
int main(){
cin>>n>>m;
rep(i,m){
scanf("%d %d", a+i, b+i);
a[i]--; b[i]--;
g[a[i]].pb(mp(b[i],i));
g[b[i]].pb(mp(a[i],i));
lft[a[i]]++;
lft[b[i]]++;
}
fill(visited, visited+n, false);
fill(usedImos, usedImos+m, false);
fill(imos, imos+n, 0);
dfsInit(0,-1);
fill(visited, visited+n, false);
dfsBridge(0);
fill(use, use+m, 0);
rep(i,m) if(isBridge[i] && use[i]==0){
useEdge(i, 2);
}
for(int i=m-1; i>=0; i--) if(use[i]==0){
useEdge(i, 1);
}
// dbg(vector<int>(use, use+m));
long ans = 0;
const long MOD = 1000000007;
long tmp = 2;
rep(i,m){
ans += tmp;
if(use[i]==2) ans += tmp;
tmp = tmp*2 %MOD;
}
cout << ans %MOD << endl;
return 0;
}
Submission Info
Submission Time
2017-10-19 23:41:11+0900
Task
C - ドライブ
User
tossy
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
2855 Byte
Status
WA
Exec Time
418 ms
Memory
48896 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:74:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", a+i, b+i);
^
Judge Result
Set Name
Sample
Subtask1
Subtask2
Score / Max Score
0 / 0
0 / 40
0 / 70
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt
Subtask1
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt
Subtask2
sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt
Case Name
Status
Exec Time
Memory
sample_01.txt
AC
6 ms
19456 KB
sample_02.txt
AC
6 ms
19456 KB
subtask1_01.txt
AC
6 ms
19456 KB
subtask1_02.txt
AC
6 ms
19456 KB
subtask1_03.txt
AC
6 ms
19456 KB
subtask1_04.txt
AC
7 ms
19584 KB
subtask1_05.txt
WA
7 ms
19584 KB
subtask1_06.txt
AC
7 ms
19584 KB
subtask1_07.txt
AC
7 ms
19584 KB
subtask1_08.txt
AC
7 ms
19712 KB
subtask1_09.txt
AC
7 ms
19584 KB
subtask1_10.txt
AC
7 ms
19584 KB
subtask1_11.txt
AC
8 ms
19584 KB
subtask1_12.txt
AC
7 ms
19584 KB
subtask1_13.txt
AC
7 ms
19712 KB
subtask1_14.txt
WA
7 ms
19584 KB
subtask1_15.txt
AC
7 ms
19584 KB
subtask1_16.txt
AC
7 ms
19584 KB
subtask1_17.txt
WA
7 ms
19584 KB
subtask1_18.txt
AC
7 ms
19584 KB
subtask2_01.txt
AC
385 ms
45824 KB
subtask2_02.txt
AC
379 ms
44544 KB
subtask2_03.txt
AC
250 ms
37740 KB
subtask2_04.txt
WA
418 ms
48896 KB
subtask2_05.txt
AC
277 ms
36224 KB
subtask2_06.txt
AC
257 ms
36480 KB
subtask2_07.txt
AC
158 ms
37100 KB
subtask2_08.txt
AC
361 ms
44032 KB
subtask2_09.txt
AC
338 ms
38272 KB
subtask2_10.txt
WA
60 ms
25600 KB
subtask2_11.txt
WA
97 ms
28160 KB
subtask2_12.txt
AC
278 ms
38384 KB
subtask2_13.txt
WA
335 ms
43776 KB
subtask2_14.txt
AC
311 ms
37248 KB
subtask2_15.txt
WA
114 ms
28288 KB